import torch
t1 = torch.tensor(4.)
t1
tensor(4.)
t1.dtype
torch.float32
t2 = torch.tensor([1.,2,3,4])
t2
tensor([1., 2., 3., 4.])
t3 = torch.tensor([[5,6], [7,8], [9,10]])
t3
tensor([[ 5, 6],
[ 7, 8],
[ 9, 10]])
t4 = torch.tensor([
[[11,12,13],
[13,14,15]],
[[15,16, 17],
[17,18,19.]]
])
t4
tensor([[[11., 12., 13.],
[13., 14., 15.]],
[[15., 16., 17.],
[17., 18., 19.]]])
t4.shape
torch.Size([2, 2, 3])
t4.dtype
torch.float32
x = torch.tensor(3.)
w = torch.tensor(4.,requires_grad = True)
b = torch.tensor(5.,requires_grad = True)
y = x * w +b
y
tensor(17., grad_fn=<AddBackward0>)
y.backward()
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.)
import numpy as np
x = np.array([[1,2],[3,4]])
x
array([[1, 2],
[3, 4]])
y = torch.from_numpy(x)
y
tensor([[1, 2],
[3, 4]])
x.dtype, y.dtype
(dtype('int64'), torch.int64)
z = y.numpy()
z
array([[1, 2],
[3, 4]])
import jovian
jovian.commit()
[jovian] Saving notebook..