What’s a Tensor and the place is it used; Tensor is an n-dimension matrix and is utilized in varied fields of machine studying, deep studying, neural networks (CNNs, RNNs) and scientific computing resulting from their means to deal with multi-dimensional knowledge effectively
In easiest phrases, it’s a knowledge construction, a complicated one, that may retailer an information with a number of attributes. Arrays, a well-liked knowledge construction shops knowledge in a single dimension, so is lists. this implies Arrays are 1-dimension tensors.
Matrices are frequent 2-dimension (2D) arrays alongside knowledge frames. Right here you retailer knowledge in grid like codecs or tables, it has rows and columns. Matrix is an array of arrays. Every aspect in itself is an array inside one other array.
The important thing right here is that it has rows & columns, and we are able to signify knowledge with multiple function, allow us to say a picture with picture identify and picture places or the kind of picture
NB: each arrays and matrices (an array of arrays) are tensors, the primary being a 1D tensor and the latter being a 2D tensor
There’s 3D, 4D, 5D,…..N-dimension tensors relying on the attributes of the info you’re attempting to signify, for instance that is how a 3D tensor will appear to be, it has rows, columns and the depth (like how a field is represented)
3D tensors are only a stack of 2D matrices, Every layer within the stack signify a 2D matrix, and the depth signifies the variety of this layers
RANKS
Tensors are n-dimension matrix, they’ve ranks relying on the worth of N
“rank” refers back to the variety of dimensions or axes of the tensor. Within the context of tensors and multi-dimensional arrays, “axes” (singular: “axis”) seek advice from the completely different dimensions alongside which knowledge is organized. Every axis represents a selected means of indexing into the info construction.
For a 1D tensor (vector), it may be conceptually considered both a row or a column, however it’s essentially a single sequence of numbers with none express route.
For two-dimension arrays you’ve got the rows and columns, which means knowledge is organized in rows and columns, and thus is of rank 2
Sensible Instance
- Rank 0: A single temperature studying.
- Rank 1: A listing of each day temperatures.
- Rank 2: A desk of temperatures for every week (days vs. occasions).
- Rank 3: A stack of such tables for various cities.
CREATING A TENSOR WITH TENSORFLOW
to create a one dimension tensor:
import tensorflow as tf
tensor1D = tf.fixed([10, 20, 30])
print(tensor1D)
to create a two dimension tensor:
import tensorflow as tf
tensor2D = tf.fixed([
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
])
print(tensor2D)
to create a 3 dimension tensor:
import tensorflow as tf
tensor3D = tf.fixed([
[
[1, 2, 3],
[4, 5, 6]
],
[
[7, 8, 9],
[10, 11, 12]
],
[
[13, 14, 15],
[16, 17, 18]
]
])
print(tensor3D)
as you may see above, 3D tensor is only a layers of 2D
Curtains closing: After we signify knowledge for machine studying, we sometimes achieve this in numerical kind, that’s the reason we’d like tensors