Lightning AI Studios: Never set up a local environment again →

Log in or create a free Lightning.ai account to track your progress and access additional course materials  

2.2 What Are Tensors (Part 1 and Part 2)

References

What we covered in this video lecture

In this video we discussed tensors as a mathematical concept: a generalization of vectors, matrices etc. However, in a computational concept, we usually think of tensors as data containers. If you are familiar with NumPy arrays, PyTorch tensors are essentially a similar concept.

In short, we can think PyTorch tensors as fancy NumPy arrays that support additional functionality, such as automatic differentation and computations on a GPU.

Additional resources if you want to learn more

For an additional take on tensors, I can also highly recommend Josh Starmer’s StatQuest video Tensors for Neural Networks, Clearly Explained!!!.

Log in or create a free Lightning.ai account to access:

  • Quizzes
  • Completion badges
  • Progress tracking
  • Additional downloadable content
  • Additional AI education resources
  • Notifications when new units are released
  • Free cloud computing credits

Quiz: 2.2 What Are Tensors?

A scalar is a

Correct

Incorrect. Vectors are rank-1 tensors.

Incorrect. Matrices are rank-2 tensors.

Suppose we have a tensor a = torch.tensor([[1, 2], [3, 4]]) representing our training dataset consisting of 2 training examples.

Correct. The [1, 2] represents the first row, and each row represents a training example.

Incorrect. Try initialize the tensor in Python and see if you can find out which numbers represent the first row.

Incorrect. The [1, 3] represents the first column, and each column represents a feature column.

Incorrect. Try initialize the tensor in Python and see if you can find out which numbers represent the first row.

We can think of an RGB color image as a … (Check all that apply)

Correct. Each color channel (R=red, G=green, B=blue) can be represented as a matrix.

Correct. Each color channel (R=red, G=green, B=blue) can be represented as a matrix. An a 3D tensor is essentially a stack of multiple matrices of the same size.

Incorrect. Hint: each color channel (R=red, G=green, B=blue) can be represented as a matrix

Incorrect. Hint: each color channel can be represented as a matrix (2D tensor) with a height and width dimension.

What can you do with a PyTorch tensor that you cannot do with a Python list? Check all that apply.

Correct. We will see later how we can run tensors on a GPU.

Incorrect. A tensor has a fixed size that cannot be changed.

Incorrect. A tensor has a fixed size that cannot be changed.

Incorrect. All elements in a tensor must have the same type.

Please answer all questions to proceed.
Watch Video 1

Unit 2.2

Videos
Follow along in a Lightning Studio

DL Fundamentals 2: Tensors and PyTorch

Sebastian
Launch Studio →
Questions or Feedback?

Join the Discussion