O'Reilly logo

Hands-On Data Analysis with NumPy and pandas by Curtis Miller

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required