From the course: PyTorch Essential Training: Deep Learning

Unlock the full course today

Join today to access over 24,900 courses taught by industry experts.

Tensor attributes

Tensor attributes

- [Instructor] Knowing attributes such as device location, data type, dimension, and rank is very important when you're doing computations with tensors. As you have learned, a tensor is a container with a fixed size that has elements of the same type. You can think of a tensor as a multidimensional array. We have already imported PyTorch, and now let's create our one-dimensional tensor called first_tensor. We'll call the device function to find out the tensor's device location, meaning the device on which the tensor is stored. Here we run the cell and see that our tensor is on the CPU. To check its data type, we'll call the dtype function. And when we ran the cell we got int64, meaning 64-bit integer. When we want to find out the shape of the tensor, we can always call its shape function and it gives us back the dimensions. Another useful function is ndim, which gives us the number of tensors, dimension, or rank. Let's go ahead and run the code. And we get one, as we have expected…

Contents