import torch
a=torch.Tensor([[1,2],[3,4]])
print(a)
print(a.type())
tensor([[1., 2.],
[3., 4.]])
torch.FloatTensor
a=torch.Tensor(2,3)
print(a)
print(a.shape)
tensor([[ 0.0000e+00, -1.1152e-01, 5.2672e-08],
[ 2.5959e-09, 4.2000e-08, 5.4373e+22]])
torch.Size([2, 3])
a=torch.ones(2,3)
print(a)
print(a.shape)
a=torch.zeros(2,3)
print(a)
print(a.shape)
a=torch.eye(2,3)
print(a)
print(a.shape)
tensor([[1., 1., 1.],
[1., 1., 1.]])
torch.Size([2, 3])
tensor([[0., 0., 0.],
[0., 0., 0.]])
torch.Size([2, 3])
tensor([[1., 0., 0.],
[0., 1., 0.]])
torch.Size([2, 3])
b=torch.Tensor(2,3)
b=torch.ones_like(b)
print(b)
print(b.shape)
tensor([[1., 1., 1.],
[1., 1., 1.]])
torch.Size([2, 3])
a=torch.rand(2,3)
print(a)
print(a.shape)
a=torch.rand(2,3)
print(a)
print(a.shape)
a=torch.normal(mean=0.0,std=torch.rand(5))
print(a)
print(a.shape)
a=torch.normal(mean=torch.rand(5),std=torch.rand(5))
print(a)
print(a.shape)
c=torch.Tensor(2,2).uniform_(-1,1)
print(c)
print(c.shape)
a=torch.arange(0,10,1)
print(a)
print(a.shape)
a=torch.linspace(2,10,3)
print(a)
print(a.shape)
a=torch.randperm(10)
print(a)
print(a.shape)
tensor([[0.9852, 0.2455, 0.0777],
[0.7583, 0.9628, 0.6174]])
torch.Size([2, 3])
tensor([[0.0693, 0.2986, 0.3640],
[0.9512, 0.7760, 0.7952]])
torch.Size([2, 3])
tensor([-0.7132, -0.0136, -0.2727, -0.3336, 0.8283])
torch.Size([5])
tensor([0.8153, 0.1946, 0.4179, 0.1585, 0.2395])
torch.Size([5])
tensor([[-0.8261, 0.1895],
[-0.5835, 0.7373]])
torch.Size([2, 2])
tensor([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
torch.Size([10])
tensor([ 2., 6., 10.])
torch.Size([3])
tensor([9, 1, 2, 4, 5, 8, 6, 3, 7, 0])
torch.Size([10])
import numpy as np
a=np.array([[1,2],[3.0,4]])
print(a)
print(a.shape)
[[1. 2.]
[3. 4.]]
(2, 2)