How to apply any function over an array in python?



I have created a function of subtraction of two number in Ipython notebook in the function I am giving the scalar input and getting scalar output .I want to know how to use the same function over an array.



Numpy provides np.vectorize helps Python functions to work on numpy arrays.

import numpy as np
vecfunc = np.vectorize(subtract) #Convert python function to vector function
result=vecfunc([3,2,1],[4,8,2]) #Call vector function to work on numpy arrays
print result