Jovian
⭐️
Sign In
In [1]:
import torch


In [2]:
t1 = torch.tensor(4.)
t1
Out[2]:
tensor(4.)
In [3]:
t1.dtype
Out[3]:
torch.float32
In [4]:
t2 =  torch.tensor([1.,2.,3.,4])
In [5]:
t2
Out[5]:
tensor([1., 2., 3., 4.])
In [6]:
t3 = torch.tensor([[5.,6],[7,8],[9,10]])
In [7]:
t3
Out[7]:
tensor([[ 5.,  6.],
        [ 7.,  8.],
        [ 9., 10.]])
In [8]:
t4 = torch.tensor([
    [[1.,2.,3],[4.,4,5]],
                 
    [[5.,6,7], [7.,8,9]]])
t4
Out[8]:
tensor([[[1., 2., 3.],
         [4., 4., 5.]],

        [[5., 6., 7.],
         [7., 8., 9.]]])
In [9]:
t1.shape
t2.shape
t3.shape
t4.shape
Out[9]:
torch.Size([2, 2, 3])
In [10]:
x = torch.tensor(3.)
w = torch.tensor(4., requires_grad=True)
b = torch.tensor(5., requires_grad=True)
In [11]:
y = w * x + b
y
Out[11]:
tensor(17., grad_fn=<AddBackward0>)
In [12]:
y.backward()
In [13]:
print('dy/dx',x.grad)
print('dy/dw',w.grad)
print('dy/db',b.grad)
dy/dx None dy/dw tensor(3.) dy/db tensor(1.)
In [14]:
import numpy as np
x=np.array([[1,2],[3,4]])
x
Out[14]:
array([[1, 2],
       [3, 4]])
In [15]:
y = torch.tensor(x)
y
Out[15]:
tensor([[1, 2],
        [3, 4]], dtype=torch.int32)
In [16]:
z = y.numpy()
z
Out[16]:
array([[1, 2],
       [3, 4]])
In [17]:
import jovian
In [ ]:
jovian.commit()
[jovian] Saving notebook..
[jovian] Creating a new notebook on https://jvn.io [jovian] Please enter your API key (from https://jvn.io ):
In [ ]: