Custom ufuncs
As mentioned earlier, we can create our own ufuncs. One way to create ufuncs is to use existing ufuncs, vectorized operations, array methods, and so on (that is, all of Numpy's existing infrastructure) to create a function that, component-wise, produces the results we want. Let's say that we didn't want to do this for some reason. If we have an existing Python function, and we merely want to make that function vectorized so that it applies to an ndarray component-wise, we can create a new vectorized version of the function with NumPy's vectorize function. Vectorize takes a function as input and gives a vectorized version of the function as output.
Vectorize is okay to use if you don't care about speed, but the function created ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access