Basic ndarray operations
In the following examples, we will use an arr2D
ndarray, as illustrated here:
arr2D
This is a 2 x 2 ndarray with values from 1
to 4
, as shown here:
array([[1, 2], [3, 4]])
Scalar multiplication with an ndarray
Scalar multiplication with an ndarray has the effect of multiplying each element of the ndarray, as illustrated here:
arr2D * 4
The output is shown here:
array([[ 4, 8], [12, 16]])
Linear combinations of ndarrays
The following operation is a combination of scalar and ndarray operations, as well as operations between ndarrays:
2*arr2D + 3*arr2D
The output is what we would expect, as can be seen here:
array([[ 5, 10], [15, 20]])
Exponentiation of ndarrays
We can raise each element of the ndarray to a certain power, as illustrated here:
arr2D ** 2
The output is shown here...