Skip to main content

Tensor Creation

Tensors are multi-dimensional arrays — the core data structure for numerical computing in Morph.


Importing the Tensor Module

module Tensor;

Creating Tensors

// Random 2×2 float tensor
a is Tensor<float>.Random(2, 2);

// All zeros
b is Tensor<float>.Zeros(3, 3);

// All ones
c is Tensor<float>.Ones(4, 4);

Real Example

From GpuBlockTensorOps.mx:

a is Tensor<float>.Random(2, 2);
b is Tensor<float>.Random(2, 2);
c is Tensor<float>.Random(2, 2);

Next Steps