numpy.all axis parameter misbehavior?

纵然是瞬间 提交于 2019-11-30 15:47:14
user2357112

axis=0 means to AND the elements together along axis 0, so a[0, 0] gets ANDed with a[1, 0], a[0, 1] gets ANDed with a[1, 1], etc. The axis specified gets collapsed.

You're probably thinking that it takes np.all(a[0]), np.all(a[1]), etc., selecting subarrays by indexing along axis 0 and performing np.all on each subarray. That's the opposite of how it works; that would collapse every axis but the one specified.

With 2D arrays, there isn't much advantage for one convention over the other, but with 3D and higher, NumPy's chosen convention is much more useful.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!