Numpy中einsum函数的一个bug

爱因斯坦求和非常强大.

首先给出一个三阶张量

1
2
3
4
>>> A = np.array([
... [[111,112],[121,122]],
... [[211,212],[221,222]]
... ])

正常的写法计算出的是正确的结果

1
2
3
4
5
6
>>> np.einsum('ijk->kij',A)
array([[[111, 121],
[211, 221]],

[[112, 122],
[212, 222]]])

简化后的写法会得到错误的答案

1
2
3
4
5
6
>>> np.einsum('kij',A)
array([[[111, 211],
[112, 212]],

[[121, 221],
[122, 222]]])
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

×