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([
[[1.,2.,3],[4.,4,5]],
[[5.,6,7], [7.,8,9]]])
t4
tensor([[[1., 2., 3.],
[4., 4., 5.]],
[[5., 6., 7.],
[7., 8., 9.]]])
t1.shape
t2.shape
t3.shape
t4.shape
torch.Size([2, 2, 3])
x = torch.tensor(3.)
w = torch.tensor(4., requires_grad=True)
b = torch.tensor(5., requires_grad=True)
y = w * x + 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.tensor(x)
y
tensor([[1, 2],
[3, 4]], dtype=torch.int32)
z = y.numpy()
z
array([[1, 2],
[3, 4]])
import jovian
jovian.commit()
[jovian] Saving notebook..
[jovian] Creating a new notebook on https://jvn.io
[jovian] Please enter your API key (from https://jvn.io ):