Useful "np.vectorize" function to match arrayfun in Matlab
In Matlab it is convenient to use arrayfun to map the function to a data array. Today I just find it out that we have the analogous one in Python. So if you want to do in Matlab : arrayfun( @(x) x*x, [ 1 : 10 ]) Then you can do it in Python : a = np.arange(1,10) np . vectorize (lambda x: x*x) ,(a ) Alternatively you can do it in R: sapply(seq( 1 , 10 ), function (x){x*x}) But please note that np.vectorize is designed for convenience, not for performance. So essentially you are still doing in a loop which may slow. Also there is one called "np.fromiter". As defined in manual, it is used for "Create a new 1-dimensional array from an iterable object. " iterable = ( x * x for x in range ( 1,10 )) np . fromiter ( iterable , float ) Don't forget the map function which is very useful too. list(map( (lambda x: x*x), a)) Ok, come back to np.vectorize, several Parameters are useful : (1)excluded: Since there may be more that one...