background: 在机器学习中如果使用Python必然会用到Numpy库,但Numpy中对多维数组进行joint/stack/sum/mean/median会用到一个参数Axis,这个参数在w3schools中没有细说,非常让人confuse例子的output.
结论:N-d数组可以根据指定axis=x沿着x轴collapse,完成后成为N-1 d数组,x轴collapse成1个元素,可以视为移除了这个维度。下面图是我在PyCharm中的实验结果,符合参考(2)的说明,不符合参考(1)对于3-D维度的推测。
关键内容:
(1) 来自参考(2)What we must know about axis numbering is that indexing always starts with the highest dimension , 参考(1)的描述就没说清first是不是highest,In a NumPy array, axis 0 is the “first” axis.
(2)
图1:1-D
图2: 2-D
参考:
(1) Numpy Axes, Explained - Sharp Sight
优点:图文详细说明了2-d ,1-d情况下Axis如何理解。有兴趣可以读读作者其他的post
缺点:没有针对3-d ,4-d做详细说明,一笔带过。下面对3-d的讨论不符合我的实验结果和参考(2)的介绍。
而且维护人在comment的内容与参考(2)矛盾:The rows of each card will be axis 0.
The columns of each card will be axis 1.
And the direction of new cards will be axis 2 。
No, Mateusz, the correct dimensions for the card example are [r,c,n]
参考(2)认为3-d中axis 0是highest
(2) Multi-dimensional Numpy array aggregation
优点:图文说明了1-d,2-d,3-d情况下Axis的使用,补充了(1)没有详细说3-d的情况,对于(1)说的不清楚的地方也有纠正,很好。
缺点:再来介绍4-d就好了,因为大家大部分都是勉强能理解3-d情况下使用Axis,毕竟3-d可以演示成3维图像。4-d开始就是完全抽象的纯数学了。