import torch
print(torch.zeros(2,3,2))
print(torch.ones(2,4))
print(torch.eye(5))#对象线为1,其余为0,单位矩阵
print(torch.rand(2,3))#[0,1]随机数
print(torch.arange(2,8))#序列
print(torch.arange(2,10,3))
tensor([[[0., 0.],
[0., 0.],
[0., 0.]],
[[0., 0.],
[0., 0.],
[0., 0.]]])
tensor([[1., 1., 1., 1.],
[1., 1., 1., 1.]])
tensor([[1., 0., 0., 0., 0.],
[0., 1., 0., 0., 0.],
[0., 0., 1., 0., 0.],
[0., 0., 0., 1., 0.],
[0., 0., 0., 0., 1.]])
tensor([[0.2293, 0.5129, 0.2397],
[0.3889, 0.5081, 0.4054]])
tensor([2, 3, 4, 5, 6, 7])
tensor([2, 5, 8])
单位矩阵:
在线性代数中,n阶单位矩阵,是一个
n
×
n
{\displaystyle n\times n}
n×n 的方形矩阵,其主对角线元素为1,其余元素为0。单位矩阵以
I
n
I
n
{\displaystyle I_{n}}I_n
InIn表示;如果阶数可忽略,或可由前后文确定的话,也可简记为
I
{\displaystyle I}
I(或者
E
{\displaystyle E}
E)。(在部分领域中,如量子力学,单位矩阵是以粗体字的1表示,否则无法与
I
{\displaystyle I}
I作区别。)
I
1
=
[
1
]
,
I
2
=
[
1
0
0
1
]
,
I
3
=
[
1
0
0
0
1
0
0
0
1
]
,
⋯
,
I
n
=
[
1
0
⋯
0
0
1
⋯
0
⋮
⋮
⋱
⋮
0
0
⋯
1
]
I
1
=
[
1
]
,
I
2
=
[
1
0
0
1
]
,
I
3
=
[
1
0
0
0
1
0
0
0
1
]
,
⋯
,
I
n
=
[
1
0
⋯
0
0
1
⋯
0
⋮
⋮
⋱
⋮
0
0
⋯
1
]
{\displaystyle I_{1}={\begin{bmatrix}1\end{bmatrix}},\ I_{2}={\begin{bmatrix}1&0\\0&1\end{bmatrix}},\ I_{3}={\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}},\ \cdots ,\ I_{n}={\begin{bmatrix}1&0&\cdots &0\\0&1&\cdots &0\\\vdots &\vdots &\ddots &\vdots \\0&0&\cdots &1\end{bmatrix}}}I_{1}={\begin{bmatrix}1\end{bmatrix}},\ I_{2}={\begin{bmatrix}1&0\\0&1\end{bmatrix}},\ I_{3}={\begin{bmatrix}1&0&0\\0&1&0\\0&0&1\end{bmatrix}},\ \cdots ,\ I_{n}={\begin{bmatrix}1&0&\cdots &0\\0&1&\cdots &0\\\vdots &\vdots &\ddots &\vdots \\0&0&\cdots &1\end{bmatrix}}
I1=[1], I2=[1001], I3=⎣⎡100010001⎦⎤, ⋯, In=⎣⎢⎢⎢⎡10⋮001⋮0⋯⋯⋱⋯00⋮1⎦⎥⎥⎥⎤I1=[1], I2=[1001], I3=⎣⎡100010001⎦⎤, ⋯, In=⎣⎢⎢⎢⎡10⋮001⋮0⋯⋯⋱⋯00⋮1⎦⎥⎥⎥⎤