Tensor Manipulation
Learn to manipulate PyTorch tensors.
We'll cover the following...
In the coming lessons, we’ll explore neural networks with the PyTorch library. Images are a form of data easily consumable by a neural network. Therefore, in many situations, neural networks can help us in automated inspection.
Before diving into the internal operators of a neural network, we must take a closer look at the data format that each component will process as input and output: the tensor.
What is a tensor?
A tensor is a multidimensional array.
Note: If you have used the NumPy module, you’ve probably manipulated
numpy.arrayobjects, which are tensors.
You can create a numpy.array object and convert it to a torch.Tensor object with the function torch.from_numpy().
In line 5, we create a torch.Tensor object from a numpy.array object.
Conversely, we can create a numpy.array object from a tensor with the Tensor.numpy() method.
In line 5, we create a random tensor sampled from a normal distribution