Learn practical skills, build real-world projects, and advance your career

Tensor operations in Pytorch

I picked five tensor operations that are interesting and useful for many fields and provide an example for each operation.

  1. new_full()
  2. randn()
  3. expand()
  4. arange()
  5. permute()

Conclusion

References

What is tensor?

Tensor is referring to high dimensional matrices(width and height), for even more dimensions which have depth, each depth layer is a matrix. Each matrix has a row or column vector, each vector consisted of scalar numbers.
1_kgzLawJmfp3i3UCG_KhfDA.png

Before we jump, let's take a quick review on data types!

A tensor can be constructed with these data types: float, integer, boolean:

1_42ia8DWx-i8DRIBaooHOvQ.png
Source

# Import torch and other required modules
import torch

1. new_full()

Return a tensor fill with a given size(width and height) and the value of the existing tensor.