Learn practical skills, build real-world projects, and advance your career
Updated 4 years ago
Intoduction to Pytorch Tensors
Tensor and its function
PyTorch is a Python-based scientific computing package that uses the power of graphics processing units. It is also one of the preferred deep learning research platforms built to provide maximum flexibility and speed. Here are few tensor functions discussed
- torch.new_tensor
- torch.new_empty
- torch.bitwise_not
- torch.clamp
- torch.div()
# Import torch and other required modules
import torch
Function 1 - torch.new_tensor
Replaces a tensor with a new tensor
# Example 1
data = torch.tensor([[1, 2], [3, 4.]])
new_data = [[[1, 2, 3],[3, 4, 5]],[[6, 7, 8],[8, 9, 10]]]
data.new_tensor(new_data)
tensor([[[ 1., 2., 3.],
[ 3., 4., 5.]],
[[ 6., 7., 8.],
[ 8., 9., 10.]]])
Here a 2 dimentional matrix tensor is replacdd with a 3-d array. The original datatype is preserved