![在这里插入图片描述](https://img-blog.csdnimg.cn/cb2b4421f393489284471d5ccd3be8f0.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2pqd196eWZ4,size_16,color_FFFFFF,t_70)
Tensor
import torch
# 生成一个指定的tensor
a = torch.Tensor([[1, 2], [3, 4]])
print(a)
print(a.type())
![在这里插入图片描述](https://img-blog.csdnimg.cn/f9c64fa17e5642fcba2ea0ff4427c891.png)
Tensor
a = torch.Tensor(2, 3)
print('Tensor', a)
print(a.type())
![在这里插入图片描述](https://img-blog.csdnimg.cn/18c8907244e24b2796a76e8dc4fae8f3.png)
ones
a = torch.ones(3, 3)
print('ones', a)
print(a.type())
![在这里插入图片描述](https://img-blog.csdnimg.cn/52d40e912d3447299c8cecf64f98ad88.png)
eye
a = torch.eye(3, 3)
print('eye', a)
print(a.type())
![在这里插入图片描述](https://img-blog.csdnimg.cn/4d22b2701dc447dcb73e87034e40ae45.png)
zeros
a = torch.zeros(3, 3)
print('zeros', a)
print(a.type())
![在这里插入图片描述](https://img-blog.csdnimg.cn/e3640cfff3a74523a8574c39df726f82.png)
zeros_like
b = torch.zeros_like(a)
c = torch.ones_like(a)
print('zeros_like', b)
print('ones_like', c)
![在这里插入图片描述](https://img-blog.csdnimg.cn/bdb8aaaa34644badbeef48a3440ccf39.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAamp3X3p5Zng=,size_20,color_FFFFFF,t_70,g_se,x_16)
rand
a = torch.rand(2, 3)
print('rand', a)
print(a.type())
![在这里插入图片描述](https://img-blog.csdnimg.cn/439d7026aa054ae98cc96bda91d369c4.png)
注意不同取值方式的变化
取单列
![在这里插入图片描述](https://img-blog.csdnimg.cn/788c7ceeff094f9db839fc2cb96fae23.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAamp3X3p5Zng=,size_20,color_FFFFFF,t_70,g_se,x_16)
取多列 又在外边套了一层列表
![在这里插入图片描述](https://img-blog.csdnimg.cn/f2c856d084be4c93bf12a6d9e16bd776.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAamp3X3p5Zng=,size_20,color_FFFFFF,t_70,g_se,x_16)
max 参照上一个
![在这里插入图片描述](https://img-blog.csdnimg.cn/1eb5bba5b42d4e16a85260d3949a3a58.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAamp3X3p5Zng=,size_20,color_FFFFFF,t_70,g_se,x_16)
randint
![在这里插入图片描述](https://img-blog.csdnimg.cn/0581c0e0476c4ff683b71bd41ac19ee8.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAamp3X3p5Zng=,size_20,color_FFFFFF,t_70,g_se,x_16)
normal
a = torch.normal(mean=0.0, std=torch.rand(5))
print('normal', a)
print(a.type())
![在这里插入图片描述](https://img-blog.csdnimg.cn/5af139f3f9fd44d48c5ff597917b7809.png)
a = torch.normal(mean=torch.rand(5), std=torch.rand(5))
print(a)
print(a.type())
![在这里插入图片描述](https://img-blog.csdnimg.cn/8bb639cbf60345eda1d78da839f58dea.png)
uniform_
a = torch.Tensor(2, 2).uniform_(-1, 1)
print('uniform_', a)
print(a.type())
![在这里插入图片描述](https://img-blog.csdnimg.cn/1df4d7c5869043f091cb571b90e151cf.png)
arange
a = torch.arange(0, 10, 1)
print('arange', a)
print(a.type())
![在这里插入图片描述](https://img-blog.csdnimg.cn/db035d174c3d4529876a0d9a23628032.png)
linspace
a = torch.linspace(1, 10, 3)
print('linspace', a)
print(a.type())
![在这里插入图片描述](https://img-blog.csdnimg.cn/20e8a198ced74810ae466a0d5fe2e33c.png)
randperm
a = torch.randperm(10)
print('randperm', a)
print(a.type())
![在这里插入图片描述](https://img-blog.csdnimg.cn/8d53489426364eb58d93075cb1f1c6b8.png)
T t()
![在这里插入图片描述](https://img-blog.csdnimg.cn/75d9ad95c83047eeb4ea3a7d1abd1a84.png?x-oss-process=image/watermark,type_ZHJvaWRzYW5zZmFsbGJhY2s,shadow_50,text_Q1NETiBAamp3X3p5Zng=,size_20,color_FFFFFF,t_70,g_se,x_16)