Python 科学计算 | 三维数组的转置运算

在 numpy 中可以使用 transpose 和 einsum 两种方法进行三维数组的转置.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
>>> x = np.arange(12).reshape(3,2,2)
>>> x
array([[[ 0, 1],
[ 2, 3]],

[[ 4, 5],
[ 6, 7]],

[[ 8, 9],
[10, 11]]])
>>> x.transpose(2,1,0)
array([[[ 0, 4, 8],
[ 2, 6, 10]],

[[ 1, 5, 9],
[ 3, 7, 11]]])
>>> np.einsum('ijk->kji',x)
array([[[ 0, 4, 8],
[ 2, 6, 10]],

[[ 1, 5, 9],
[ 3, 7, 11]]])
LaTeX standalone 环境输出图片格式文件 Python 基础 | 语法糖和一些关键字

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×