import torch
import numpy as np
print(torch.empty(5,3))
print(torch.rand(5,3))
print(torch.zeros(5,3,dtype=torch.long))
print(torch.zeros(5,3).long())
print(torch.tensor([5.5,3]))
x = torch.tensor([5.5,3])
print(x.shape)
y = x.new_ones(5,3)
print(y.type())
y = x.new_ones(5,3,dtype=torch.double)
print(y)
y = torch.rand_like(x, dtype=torch.float)
print(y)
x = torch.rand(5,3)
y = torch.rand_like(x)
print('x:{} \n y:{}'.format(x,y))
print(x+y)
print(torch.add(x,y))
y.add_(x)
print(y)
print(y.shape)
y = y.view(15)
print(y)
print(y.shape)
x =torch.randn(1)
print(x)
print(x.data)
print(x.grad)
print(x.item())
y = y.view(3,-1)
print(y.shape)
y = y.transpose(1,0)
print(y.shape)
a = torch.ones(5)
b = a.numpy()
print(a,',',b)
b[1] = 2
print(a)
a = np.ones(5)
b = torch.from_numpy(a)
np.add(a,1,out=a)
print(a,',',b)
x = torch.randn(5)
if torch.cuda.is_available():
device = torch.device("cuda")
y = torch.ones_like(x,device=device)
x = x.to(device=device)
z = torch.add(x,y)
print(z)
print(z.to('cpu', torch.double))
print(z.cpu())