# What is the tensor in tensorflow?

2020-11-06 20:53:47

## Tensor( tensor )

“ tensor ” The word was originally used by William · Ron · Hamilton is in 1846 In introducing . Yes , It's the Hamilton who invented quaternion ：

• Tensor It's actually a multidimensional array （multidimensional array）

• Tensor The goal is to be able to create a higher dimensional matrix 、 vector .

### An example of color

Color image file （RGB） It's usually handled as 3-d tensor, Every 2d array Medium element Represents a pixel ,R representative Red,G representative Green,B representative Blue

## Multidimensional arrays

Draw a cube in three dimensions ：

Higher dimensional tensors :

## Initialize a vector

### 0 dimension

``````tf.tensor(1).print();
``````

### 1 dimension

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

### 2 dimension

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

### 3 dimension

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

### 4 dimension

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

### 5 dimension

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

### 6 dimension

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

For more articles, please follow my blog Alili The big bang at the front end Subscription number : `Alili The big bang at the front end `