I\'ve found that the numpy.vectorize allows one to convert \'ordinary\' functions which expect a single number as input to a function which can also convert a list of inputs
If you want to use vectorized implementation of your method you can use excluded
parameter like following:
class MyClass:
def __init__(self, data):
self.data = data
self.my_vectorized_func = np.vectorize(self.my_func, excluded='self')
def my_func(self, x):
return pow(x, self.data)
With this, you can use your method like the non-vectorized one:
In[1]: myclass = MyClass(3) # '3' will be the power factor of our function
In[2]: myclass.my_vectorized_func([1, 2, 3, 4, 5])
Out[3]: array([ 1, 8, 27, 64, 125])