指定所有元素(默认float):
torch.tensor([[1,2,3,][4,5,6]])
指定shape的float型:
# generate a float tensor with shape (1,3) torch.rand(1,3)
高斯分布的指定shape(float):
# generate a float tensor with shape (1,3) using Normal(Guassian) distribution torch.randn(1,3) # or torch.randn((1,3)) # work the same as the last one.
指定shape的int型:
# shape (3,4), low=1, high=6 torch.randint(1,6,(3,4))numpy
默认import numpy as np了
numpy中在random中集成的,需要np.random.xxx,用法和torch的差不多。
指定所有元素(默认float):
np.array([[1,2,3],[4,5,6,]])
指定shape的float型:
# generate a float numpy array with shape (1,3) np.random.rand(1,3) # wrong below! np.random.rand((1,3))
高斯分布的指定shape(float):
# generate a float tensor with shape (1,3) using Normal(Guassian) distribution np.random.randn(1,3) # wrong below! np.random.randn((1,3))
指定shape的int型:
# shape (3,4), low=1, high=6 np.random.randint(1,6,(3,4))



