Numpy中axis的理解
size()和max()中的含义
size()和max()中的含义
以前我理解axis=0代表行,axis=1代表列; 但是这种含义在函数size()和max()中恰恰相反; 其实不是这样的,我们回到单词axis本身,它的意思是“轴”,没错轴就是代表一个方向,像x轴,y轴,如图所示: axis=0代表的就是x轴方向; axis=1代表的就是y轴方向; 这样函数size()和max()就能解释得通了:
import numpy
as np
a
= np
.array
([[1, 2, 3], [4, 5, 6]])
np
.size
(a
, axis
=0)
>>> 2
np
.size
(a
, axis
=1)
>>> 3
np
.max(a
, axis
=0)
>>> array
([4, 5, 6])
np
.max(a
, axis
=1)
>>> array
([3, 6])
Matlab中也是一样的道理,很多函数都与Matlab中一样,也有不同,比如: Matlab中reshape()是按列读按列写; Python中reshape()默认是按行读按行写; 使用时需要留心!