Arbitrary Shape Tensor

Overview


Example 1


To create a tensor of arbitrary shape, you can pass a shape array to the tensor method, to instruct the method how to shape the first parameter (the array)


const shape = [2, 3]; // 2 rows, 3 columns
const tensor = tf.tensor([1.0, 2.0, 3.0, 10.0, 20.0, 30.0], shape);
tensor.print(); // print Tensor values

// Output: [[1 , 2 , 3 ],
//          [10, 20, 30]]

//if not created within tidy, must dipose of tensor
tensor.dispose();
				
Try it!


Contents