May 2019
Beginner
528 pages
29h 51m
English
NumPy offers dozens of standalone universal functions (or ufuncs) that perform various element-wise operations. Each performs its task using one or two array or array-like (such as lists) arguments. Some of these functions are called when you use operators like + and * on arrays. Each returns a new array containing the results.
Let’s create an array and calculate the square root of its values, using the sqrt universal function:
In [1]: import numpy as npIn [2]: numbers = np.array([1, 4, 9, 16, 25, 36])In [3]: np.sqrt(numbers)Out[3]: array([1., 2., 3., 4., 5., 6.])
Let’s add two arrays with the same shape, using the add universal function:
In [4]: numbers2 = np.arange(1, 7) * 10In [5]: numbers2Out[5]: array([10, ...
Read now
Unlock full access