NumPy Arithmetic and Statistics - Computations and Aggregations

1. Computations on NumPy Arrays

The reason for NumPy’s importance in the Pythonic data science world is its ability to perform computations in a fast and efficient manner. Now that we are familiar with the basic nuts and bolts of NumPy, we are going to dive into learning it to perform computations.

NumPy provides the so-called universal functions (ufuncs) that can be used to make repeated calculations on array elements in a very efficient manner. These are functions that operate on nD-arrays in an element-by-element fashion. Remember the vectorized operations from earlier.

Mathematical Functions

What are some of the most common and useful mathematical ufuncs available in the NumPy package? Let’s explore them with some concrete examples.

The arithmetic operators, as shown in the code widget below, are conveniently wrapped around specific functions built into NumPy; for example, the + operator is a wrapper for the add ufunc.

Run the code in the widget below, tweak the inputs, and observe the outputs of the print statements.

Get hands-on with 1400+ tech skills courses.