Is there a more efficient way than using numpy.asarray() to generate an array from output in the form of a list?
This appears to be copying everything in memory, which doesn't seem like it would be that efficient with very large arrays.
(Updated) Example:
import numpy as np
a1 = np.array([1,2,3,4,5,6,7,8,9,10]) # pretend this has thousands of elements
a2 = np.array([3,7,8])
results = np.asarray([np.amax(np.where(a1 > element)) for element in a2])
elementis larger then all elements ina1, it is just the largest element ofa1. In any case the approach will scale very badly for largea1for this kind of function, so what are you actually doing here? Alsonp.frompyfuncdoesn't really speed up things. Note that the copying here should be very unimportant compared to the actual work done, trying to optimize things without knowing where your time is spend is usually a bad idea...