Jovian
⭐️
Sign In
In [1]:
import torch
In [2]:
x = torch.tensor(3.)
w = torch.tensor(4., requires_grad=True)
b = torch.tensor(5., requires_grad=True)
In [3]:
y = w * x + b
y
Out[3]:
tensor(17., grad_fn=<AddBackward0>)
In [4]:
y.backward()
In [5]:
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 [6]:
import numpy as np
In [7]:
x = np.array([[1, 2], [3, 4]])
x
Out[7]:
array([[1, 2],
       [3, 4]])
In [8]:
y = torch.from_numpy(x)
y
Out[8]:
tensor([[1, 2],
        [3, 4]], dtype=torch.int32)
In [9]:
x.dtype, y.dtype
Out[9]:
(dtype('int32'), torch.int32)
In [10]:
z = y.numpy()
z
Out[10]:
array([[1, 2],
       [3, 4]])
In [11]:
z.dtype
Out[11]:
dtype('int32')
In [1]:
import jovian
In [ ]:
jovian.commit()
[jovian] Saving notebook..
In [ ]: