Tensors

Overview


Pre-Populated Tensors


when creating a tensor, you need to specify the number of indices, and the size of the array for each index. This is done by specifying an array whihc has a length equal to number of indices, and each value equal to the size of the array at each index. For example, the following code creates a 2x2 matrix. It fills it with zeroes.


let tensor = tf.zeros([2,2])

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


When a tensor is created, it is created as immutable. To create a tensor that can change its values, make a call to the variable function.


let tensor = tf.variable(tf.zeros([2,2]))

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


To preopulate the tensore with random values drawn from the normal distribution, use the randomNormal function.


let tensor = tf.randomNormal([2,2])
				

Contents