We make two arrays first.
1 | a = np.array([[2,2,2],[3,3,3],[4,4,4]]) |
Arithmetic Operation
As numbers, it is possible to add, minus, multiple, divide…
1 | #add |
For all of them, it executes corresponding element in the array.
Functional Operation
Besides, it can also do for Trigonometric function.
1 | np.sin(a) |
For the cos and tan or others is same.
We can do some conditions, but the output is boolean value
1 | a>3 |
If we wanna compute the value of multiplication of the matrix, we need a method of the numpy
1 | np.dot(a,b) |
For an array, we can use some inner functions to compute it conviently
1 | np.sum(a) #27 |
Specially, we can add one more parameter and it will execute on every rows or columns
1 | np.sum(a, axis=0) #column |
It is available for min and max as well.
Besides, we can output the index of the maximum number or minimum
1 | # make a new array |
Computing the value of average
1 | np.mean(A) #6.5 |
And median
1 | np.median(A) #6.5 |
There is a method, it makes an increase array and the element is summed by last element
1 | np.cumsum(A) |
Similarly, a minus method. But there are some differences. This method is still keep the type of the original array and the number of the element in every row will decrease one.
1 | np.diff(A) |
A detection method to check whether it is zero or not, if it is not zero, the position of it will be written down. e.g. (0,0), (0,1), (0,2)…
1 | np.nonzero(A) |
It also has sort method, differently, it sorts every row, not all elements
1 | np.sort(A) |
It is possible to transpose matrix
1 | np.transpose(A) |
And there is a method called clip, it has three parameters, first is the array, second is the minimal value, last is the maximal value and it will return another array.
1 | np.clip(A, 3, 9) |
As we see, the element bigger than you set, they will be the set one and for minimal value is also.
Lastly, let us see random method.
1 | r = np.random.random((2,2)) |
It will generate the number between 0 to 1.
Thanks for your reading, I hope it is useful for you.
End
Illustrator / Cagy
Text / Cagy
Editor / Cagy
Design / Cagy