Ravindra BagaleCourses & study guides मराठी Track your progress

44. Install PyTorch and First Tensors

44.2 What Is a Tensor

Why. NumPy arrays hold numbers. PyTorch tensors do too — and they track gradients when needed for learning.

What. A tensor is a multi-dimensional number container: scalar, vector, matrix, or higher. Same spirit as NumPy ndarray, with autograd superpowers.

How.

Make three tensors

  1. From a Python list.
  2. Zeros / ones helpers.
  3. Check .shape and .dtype.
import torch
x = torch.tensor([1.0, 2.0, 3.0])
Z = torch.zeros(2, 3)
print(x, x.shape, x.dtype)
print(Z)

Ravindra Bagale's Tip

Tensor = smart box of numbers. Shape nehmi print kara — debug 50% solve.