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

Vectorization with ufuncs

ufuncs are special NumPy functions designed to work with arrays; in particular, they support vectorization. A vectorized function is applied component-wise to the elements of an array. These are often highly optimized functions, running under the hood on a faster language, such as C.

In the following, we see some common ufuncs, many of which are mathematical:

Let's explore some applications of ufuncs. The first thing we're going to do is find the sign of every element in arr1, that is, whether it is positive, negative, or zero:

Then with this sign, I multiply this array with arr1. The result is as if we took the ...

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