MATH OPERATIONS AND ARRAYS
Listing 2.9 displays the content of mathops_array1.py that illustrates how to compute exponents of the elements in a NumPy array.
LISTING 2.9: mathops_array1.py
import numpy as np
arr1 = np.array([1,2,3])
sqrt = np.sqrt(arr1)
log1 = np.log(arr1)
exp1 = np.exp(arr1)
print('sqrt:',sqrt)
print('log1:',log1)
print('exp1:',exp1)
Listing 2.9 contains a NumPy array called arr1 followed by three NumPy arrays called sqrt, log1, and exp1 that are initialized with the square root, log, and exponential value of the elements in arr1, respectively. The three print() statements display the contents of sqrt, log1, and exp1. The output from launching Listing 2.9 is here:
('sqrt:', array([1. , 1.41421356, 1.73205081]))
('log1:', array([0. , 0.69314718, 1.09861229]))
('exp1:', array([2.71828183, 7.3890561, 20.08553692]))