使用
numpy.apply_along_axis()。假设您的矩阵是2D,则可以这样使用:
import numpy as npmymatrix = np.matrix([[11,12,13],[21,22,23],[31,32,33]])def myfunction( x ): return sum(x)print np.apply_along_axis( myfunction, axis=1, arr=mymatrix )#[36 66 96]

使用
numpy.apply_along_axis()。假设您的矩阵是2D,则可以这样使用:
import numpy as npmymatrix = np.matrix([[11,12,13],[21,22,23],[31,32,33]])def myfunction( x ): return sum(x)print np.apply_along_axis( myfunction, axis=1, arr=mymatrix )#[36 66 96]