Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a tensor and a multi-d matrix in Tensorflow?

I am following the tensorflow CNN tutorial and bumped into the question of what programatically is the difference between a 'tensor' and a multi-dimensional matrix in Tensorflow and in general as well.

I tried to research on my own what a tensor is and what I have found out is: it it can be of order n, where every element hold information of n dimensions. E.g. if we have a tensor A and a data point with coordinates (3,2,5,4), then we are talking about a 4-D tensor A with one element. Is that correct?

Other articles that I found say that a tensor is the same as an array with the difference that a tensor's elements may transform. Again I don't see the difference betwen a tensor and a normal multi-dimensional array. We can always apply a function on the array and transform the elements.

Could you please try to clarify the definitions/properties and differences?

like image 376
KDX2 Avatar asked Feb 03 '18 15:02

KDX2


People also ask

What is difference between matrix and tensor?

In a defined system, a matrix is just a container for entries and it doesn't change if any change occurs in the system, whereas a tensor is an entity in the system that interacts with other entities in a system and changes its values when other values change.

Are tensors just multidimensional matrices?

A tensor is a generalization of vectors and matrices and is easily understood as a multidimensional array. In the general case, an array of numbers arranged on a regular grid with a variable number of axes is known as a tensor.

Are tensors multi dimensional?

Tensors are multi-dimensional arrays with a uniform type (called a dtype ). You can see all supported dtypes at tf. dtypes. DType .

What does tensor mean in TensorFlow?

A tensor is a generalization of vectors and matrices to potentially higher dimensions. Internally, TensorFlow represents tensors as n-dimensional arrays of base datatypes. Each element in the Tensor has the same data type, and the data type is always known.


1 Answers

Slide 7 of this presentation has a nice visualization of various tensors.

https://www.slideshare.net/yokotatsuya/principal-component-analysis-for-tensor-analysis-and-eeg-classification

I wondered the same in the beginning. The answer is mundane though.

A "tensor" is the general purpose word given to an N-dimensional set of values. We have mathematical names for the low-rank tensors: scalars, vectors, matrices.

In tensorflow the rank of a tensor is its dimensionality. Here are some examples:

---------------------------------------------------------------
| Rank of  | Math     | Example                               |
| tensor   | entity   |                                       |
---------------------------------------------------------------
|    0     | Scalar   | x = 42                                |
|    1     | Vector   | z = [10, 15, 20]                      |
|    2     | Matrix   | a = [[1 0 2 3],                       |
|          |          |      [2 1 0 4],                       |
|          |          |      [0 2 1 1]]                       |
|    3     | 3-Tensor | A single image of shape:              |
|          |          | [height, width, color_channels]       |
|          |          | ex: [1080, 1920, 3]                   |
|    4     | 4-Tensor | A batch of images with shape:         |
|          |          | [batch_size, height, width, channels] |
|          |          | ex: [10, 1080, 1920, 3]               |
|    N     | n-dim    | You get the idea...                   |
|          | Tensor   |                                       |
---------------------------------------------------------------
like image 73
David Parks Avatar answered Sep 28 '22 08:09

David Parks