Jovian
⭐️
Sign In
In [1]:
import torch
In [3]:
t1=torch.tensor(4.)
In [7]:
print(t1.dtype)
torch.float32
In [8]:
t1=torch.tensor(4)
In [9]:
print(t1.dtype)
torch.int64
In [10]:
t2=torch.tensor([1.,2,3,4])
t2.dtype
Out[10]:
torch.float32
In [11]:
t3=torch.tensor([[1,2,3],[4,5,6]])
t3.shape
Out[11]:
torch.Size([2, 3])
In [12]:
t3
Out[12]:
tensor([[1, 2, 3],
        [4, 5, 6]])
In [38]:
a=torch.tensor([3.],requires_grad=True)
b=torch.tensor([15.],requires_grad=True)
c=a*b*a*b
c
Out[38]:
tensor([2025.], grad_fn=<MulBackward0>)
In [39]:
c.backward()
In [40]:
print(b.grad)
tensor([270.])
In [55]:
import numpy as np
x=np.array([[1,2],[3,4]])
x
y=torch.tensor(x)
z=y.numpy()
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) <ipython-input-55-6615583db68a> in <module> 4 y=torch.tensor(x) 5 z=y.numpy() ----> 6 z1=z.torch() AttributeError: 'numpy.ndarray' object has no attribute 'torch'
In [54]:
x.dtype, y.dtype, z.dtype
Out[54]:
(dtype('int32'), torch.int32, dtype('int32'))
In [57]:
import jovian
In [ ]:
jovian.commit()
[jovian] Attempting to save notebook..
In [ ]:
 
In [ ]: