Tensors

Overview


The tensor-flow library is an external library that is not pre-loaded on the davinci platform.

Tensors


Tensors are a generalization of the matrix/vector concept. If you think of a vector as being a one-dimensioanl array of numbers, and matrices as being a two-dimensional array of numbers, then you can think of a tensor as being a n-dimensional array of numbers. That is, its a collection of numbers that are indexed by n indices.


tf.tensor( value, shape, dataType)
				


  • value - the value of the tensor stated as an array
  • shape - (optional) if not present, the shape will be inferred from the value
  • dataType - (optional) specifies the type of data contained in the tensor. Will be inferred if not present

Simple Examples


Create a simple scalar


let input = tf.tensor(2);
				
Try it!

Create a simple 1-dimensional tensor


let input = tf.tensor([1, 2, 1, 1]);
				
Try it!

Create a simple 2-dimensional tensor


let input = tf.tensor([[1, 2, 1, 1]]);
				
Try it!

Reshaping a Tensor


Once a tensor has been created, you can create other tensors with the same values, but different shape by using the reshape method.


let x = tf.tensor([1, 2, 1, 1]);
let y = tf.reshape(x, [2,2]);
				
Try it!

Sample Code


Contents