![]() |
VOOZH | about |
Tensors are multidimensional arrays, fundamental to TensorFlow's operations and computations. Understanding key concepts like tensor shape, size, rank, and dimension is crucial for effectively using TensorFlow in machine learning projects.
In this article, we are going to understand tensor and its properties.
In TensorFlow, tensors are the basic building blocks used to represent data. A tensor can be thought of as a multi-dimensional array, similar to a matrix but with an arbitrary number of dimensions. Tensors can hold various data types, including integers, floating-point numbers, and strings.
Tensors are important in deep learning frameworks like TensorFlow and PyTorch. The tensors are responsible to provide insights into the structure, dimensions, and size of the tensors. The properties of tensor includes Shape, Rank, Axis and Size.
Tensor shape refers to the layout or structure of a tensor, which defines the number of dimensions and the size of each dimension in the tensor. It describes how many elements are along each axis of the tensor.
Output:
Tensor shape: (2, 3)
Tensor shape is crucial in TensorFlow as determines how the data is organized and how operations can be applied to the tensor. TensorFlow provides methods to get and manipulate the shape of a tensor, allowing developers to work with tensors effectively in machine learning models and other numerical computations.
Tensor size refers to the total number of elements in a tensor. It is the product of all the dimensions (sizes) of the tensor. In other words, it represents the total amount of data stored in the tensor.
Output:
Tensor size: tf.Tensor(6, shape=(), dtype=int32)
Tensor rank, also known as the tensor's number of dimensions, is a fundamental concept in TensorFlow. It indicates the number of dimensions present in a tensor.
Here's a brief overview of tensor rank:
Output:
Rank of scalar: 0
Rank of vector: 1
Rank of matrix: 2
Rank of 3D tensor: 3
Tensor dimension refers to the length along a particular axis of a tensor. In simpler terms, it is the size or extent of a tensor along a specific direction. Each axis of a tensor corresponds to a dimension, and the number of dimensions in a tensor is its rank.
Output:
Tensor shape: (2, 3)
Length of first dimension: 2
Length of second dimension: 3