table of Contents
(1) adding an element corresponding to an adder ---
(2) subtracting the corresponding elements of the subtraction ---
(3) multiplied by the corresponding elements of the multiplication ---
(4) dividing the corresponding element of division ---
1. The four operations
Math power
Creating an array
import numpy as np
arr1=np.arange(4).reshape(2,2)
print('arr1:',arr1)
arr2=np.array([[1,2],[1,2]])
print('arr2:',arr2)
(1) adding an element corresponding to an adder ---
arr_new=arr1+arr2
print('arr_new:',arr_new)
(2) subtracting the corresponding elements of the subtraction ---
arr_new=arr1-arr2
print('arr_new:',arr_new)
(3) multiplied by the corresponding elements of the multiplication ---
arr_new=arr1*arr2
print('arr_new:',arr_new)
(4) dividing the corresponding element of division ---
Note that the denominator can not be 0
arr_new=arr1/arr2
print('arr_new:',arr_new)
(5) exponentiation
arr_new=arr1**arr2
print('arr_new:',arr_new)
2. Compare operation
>= <= > < == !=
print('arr1>=arr2:',arr1>=arr2)
print('arr1<=arr2:',arr1<=arr2)
print('arr1>arr2:',arr1>arr2)
print('arr1<arr2:',arr1<arr2)
print('arr1==arr2:',arr1==arr2)
print('arr1!=arr2:',arr1!=arr2)
3. logical operation
or any equivalent of each position for comparison, the same as long as it is a True
all equivalent and each memory location than the right, must be all the same, it is True
print(np.any(arr1==arr2))
print(np.all(arr1==arr2))