What is a Tensor in TensorFlow?

Tensor

The term “tensor” was first introduced by William Rowan Hamilton in 1846. Yes, that’s the Hamilton who invented quaternions:

Figure 3

  • A Tensor is actually a multidimensional array

  • The purpose of Tensor is to be able to create higher-dimensional matrices and vectors.

Figure 1

Color Example

Color image files (RGB) are generally processed into 3-d tensors, where each element in the 2d array represents a pixel, R represents Red, G represents Green, B represents Blue

Figure 2

Multidimensional Arrays

Figure 4

Drawing a three-dimensional tensor as a cube:

Figure 5

Higher-dimensional tensors:

Figure 6

Initializing a Vector

0-Dimensional

tf.tensor(1).print();

1-Dimensional

tf.tensor([1, 2, 3, 4]).print();
// or
tf.tensor1d([1, 2, 3]).print();

2-Dimensional

tf.tensor([[1, 2], [3, 4]]).print();
// or
tf.tensor2d([[1, 2], [3, 4]]).print();

3-Dimensional

tf.tensor([[[1], [2]], [[3], [4]]]).print();
// or
tf.tensor3d([[[1], [2]], [[3], [4]]]).print();

4-Dimensional

tf.tensor([[[[1], [2]], [[3], [4]]]]).print();
// or
tf.tensor4d([[[[1], [2]], [[3], [4]]]]).print();

5-Dimensional

tf.tensor([[[[[1], [2]], [[3], [4]]]]]).print();
// or
tf.tensor5d([[[[[1], [2]], [[3], [4]]]]]).print();

6-Dimensional

tf.tensor([[[[[[1],[2]],[[3],[4]]],[[[5],[6]],[[7],[8]]]]]]).print();
// or
tf.tensor6d([[[[[[1],[2]],[[3],[4]]],[[[5],[6]],[[7],[8]]]]]]).print();

Article Link:

https://alili.tech/en/archive/eujpibnlnp8/

# Latest Articles