DEV Community

loading...
Cover image for Tensor explained

Tensor explained

akramnarejo profile image Akram Narejo ・1 min read


TensorFlow is the framework for dealing with deep-learning the sub branch of machine learning which is the most powerful tool to work on the unstructured data like images and speech recognition.

So the word Tensor in TensorFlow represents the multidimensional array or the combination of scalar and vectors which flows through the graph or the network of layers.

let me explain the scalar, vector(array) and matrix(multidimensional array) for you.


Scalar is just a value without any direction or axis and it's a rank 0 tensor with shape(). There are many ranks in tensor.

tf.constant(4)

Vector is an array like combination of values having the direction or dimension of axis 1 called rank 1 tensor with shape(3,).

tf.constant([1,2,3])

Matrix is a vector with dimension of 2 axis called as rank 2 tensor with shape(2,3).

tf.constant([[1,2,3],
             [4,5,6]])

tensor is the multidimensional array with axis more than 2 with the shape(2,2,3).

tf.constant([[[1,2,3],
              [4,5,6]],
             [[7,8,9],
              [10,11,12]],])

tensor can be converted to numpy by using np.numpy() or tensor.numpy()

Discussion (0)

pic
Editor guide