In this article we show how to do simple numerical operations with arrays.
Element-wise operations
Simple calculations are very straightforward with NumPy arrays.
Basic arithmetic operations (+ - * / **) can all be used with arrays. The main thing to keep in mind is that most operations are done element-wise.
a=numpy.array([1.0,2.0,3.0]) b=2.0
print(a*b) # output: [ 2. 4. 6.]
print(a+b) # output: [ 3. 4. 5.]
print(a*a) # output: [ 1. 4. 9.]
Elementary functions
NumPy provides also a wide range of elementary mathematical functions (sin, cos, exp, sqrt, log, …) that work with arrays (as well as single values). In many ways NumPy can be used as a drop-in replacement for the math module.