tenso

In machine learning world tensors are multi-dimensional arrays used to represent and manipulate data. They are a fundamental data structure in many machine learning frameworks, such as TensorFlow and PyTorch.

Hello future scientists, Tensors can have different number of dimensions or ranks, which determine their shape and the number of axes tensor possess. In simple words it is a data structure to store data. Some people might say its a container for numbers, because most of the time you will store numbers only.

Understand Basic Concepts

Scalar : Scalars do not have any associated direction or orientation. They are considered to be one-dimensional entities. examples are, mass (e.g. 5 kg), temperature (e.g. 25 degrees Celsius), time (e.g. 10 seconds), speed (e.g. 50 km/h), and energy (e.g. 100 Joules).

Vector : A vector is a mathematical object that represents both magnitude and direction. We can say it is a quantity that has both a size and a specific orientation in space. examples are, displacement (e.g. 5 meters north), velocity (e.g. 30 meters per second east).

Metric : It is a function that measures the distance between pairs of elements in a set.

So we can say like, scalar < vector < metric < tensor

0D Tensor/Scalar

What is 0D tensor ? It is also known as a scalar, it is a tensor of rank zero. It is the simplest form of a tensor and represents a single value without any dimensions or axes.

1D Tensor/Vector

What is 1D tensor ? It can be thought of as a list or vector of values. 1D tensors are widely used in machine learning and deep learning algorithms, as they provide a convenient way to represent and process sequential data.

a = np.array([1,2,3,4])

2D Tensor/Matrices

What is 2D tensor ? It often referred to as a matrix and it is a tensor of rank 2 that represents a grid of values organized in rows and columns. Actually it extends the concept of 1D tensor by adding a second dimension.

a = np.array([1,2,3],[4,5,6],[7,8,9])
[[1,2,3],
[4,5,6],
[7,8,9]]

3D Tensor

A 3D tensor is a tensor of rank 3 that represents data in a three-dimensional space. You can simply imagine it like a cube-like structure with three axes or dimensions.

3D tensors are commonly used to represent volumetric data such as 3D images or videos. Let’s see a example of 3D tensor.

Consider a 3D tensor representing a color image. Suppose we have an image with a resolution of 128 pixels in width, 128 pixels in height, and three color channels (red, green, and blue).

So the shape will be (128, 128, 3), indicating that it has a width of 128, a height of 128, and three color channels. Remember each element of the 3D tensor corresponds to a pixel in the image.

ND Tensor

It is also known as an N-dimensional tensor and it is a tensor of rank N, where N represents the number of dimensions or axes in the tensor. We can also think of it as a multi-dimensional array with N indices. Its like a video with collection of images.

Example,

Consider a dataset of grayscale images, where each image has a resolution of 64 pixels in width and 64 pixels in height. Let’s assume we have a collection of 100 images.

In this case, the dataset can be represented as an ND tensor. The tensor would have a shape of (100, 64, 64), indicating that it has 100 images, each with a width of 64 pixels and a height of 64 pixels.

ND tensors allow us to represent and manipulate data with multiple dimensions. They are used in various domains and applications, for example in natural language processing.

Also check out: Machine Learning

Conclusion

This was my understanding about tensor and I hope you must learned something. Understanding tensors is crucial for practitioners in fields such as computer vision, natural language processing, and scientific simulations, as they provide a common language and framework for handling multi-dimensional data.

FAQ

Q: What is a tensor?

Ans: A tensor is a mathematical object that represents multi-dimensional data. It can be thought of as a generalization of scalars, vectors, and matrices to higher dimensions.

Q: How are tensors different from matrices?

Ans: Matrices are 2D tensors, meaning they have two dimensions: rows and columns. Tensors, on the other hand, can have any number of dimensions, including 0 (scalar), 1 (vector), 2 (matrix), and higher.

Q: Where are tensors used?

Ans: Tensors are used in various fields, including mathematics, physics, engineering, and computer science. They are particularly prevalent in machine learning and deep learning, where they serve as the basic data structure for representing and manipulating data.

By Akshay Tekam

software developer, Data science enthusiast, content creator.

Leave a Reply

Your email address will not be published. Required fields are marked *