May 2019
Beginner
528 pages
29h 51m
English
array OperatorsNumPy provides many operators which enable you to write simple expressions that perform operations on entire arrays. Here, we demonstrate arithmetic between arrays and numeric values and between arrays of the same shape.
arrays and Individual Numeric ValuesFirst, let’s perform element-wise arithmetic with arrays and numeric values by using arithmetic operators and augmented assignments. Element-wise operations are applied to every element, so snippet [4] multiplies every element by 2 and snippet [5] cubes every element. Each returns a new array containing the result:
In [1]: import numpy as npIn [2]: numbers = np.arange(1, 6)In [3]: numbersOut[3]: array([1, 2, 3, 4, 5])In [4]: numbers * ...
Read now
Unlock full access