python - Iterating over Numpy matrix rows to apply a function each? -


i want able iterate on matrix apply function each row. how can numpy matrix ?

use numpy.apply_along_axis(). assuming matrix 2d, can use like:

import numpy np mymatrix = 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] 

Comments

Popular posts from this blog

matlab - How to equate a structure array to structure array -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -