Tensor with PyTorch🔥
Starting with tensor, you requires a little knowladge of Python, Jupitor NodeBook that requires Anaconda and little bit of programming knowledge
Installation of Python 3.8
https://www.python.org/downloads/
Latest is 3.8
Installation of Jupitor Notebook
Now we are good to go ..
First we require to import torch
Torch is an open-source machine learning library, a scientific computing framework, and a script language based on the Lua programming language.
Tensors, defined mathematically, are simply arrays of numbers, or functions, that transform according to certain rules under a change of coordinates, Tensor can be any dimentional, mertic is tensor but viseversa is not true.
6. here means its Datatype is float , This is our first single value tensor
We can also use 2D metric inside tensor
A tensor of specific data type can be constructed by passing a torch.dtype
and/or a torch.device
to a constructor or tensor creation op:
>>> torch.zeros([2, 4], dtype=torch.int32)
tensor([[ 0, 0, 0, 0],
[ 0, 0, 0, 0]], dtype=torch.int32)
>>> cuda0 = torch.device('cuda:0')
>>> torch.ones([2, 4], dtype=torch.float64, device=cuda0)
tensor([[ 1.0000, 1.0000, 1.0000, 1.0000],
[ 1.0000, 1.0000, 1.0000, 1.0000]], dtype=torch.float64, device='cuda:0')
numPy
NumPy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python
Here we pass numPy array inside tensor
We can re use the torch object as here we assigned zeros in one var and with that var we call another one
Stride
Stride is the jump necessary to go from one element to the next one in the specified dimension dim
.
Stride gives us tuple in results
Random
Tensor should be a tensor containing probabilities to be used for drawing the binary random number.
Inverse of that random is call via pinverse
These are some call with tensor using torch :
For indepth knowlegde checkout : https://pytorch.org/docs/stable/tensors.html
For linear regression model>> https://medium.com/@vshwsnahar3/linear-regression-using-pytprch-7a28399891cb