How are tensors created using PyTorch

Parameters

The following parameters are required by the tensor() function:

  • data (array_like): This is the initial data for the tensor. It can be a list, tuple, NumPy, scalar, or other types.

  • dtype: This is the desired data type of returned tensor and is optional.

  • device: This is the device of the constructed tensor. If it is None and the data is a tensor, then the device of the data is used. Otherwise, it is built on the CPU.

  • requires_grad: If autograd is enabled it should record operations on the returned tensor. This is an optional parameter.

  • pin_memory: If it is set, then the returned tensor would be allocated in the pinned memory. This is an optional parameter.

Create tensors using PyTorch

Tensors in PyTorch have equivalent functions as their NumPy counterparts like ones(), zeros(), rand(), randn(), and so on.

In the following example, we create four tensors of different dimensions:

Read more here: Source link