In this post we are going to have a look at some of the mathematical functions which can be used with numpy arrays.Also there will be details regarding the syntax of these functions.There are many mathematical functions to be used but this post will cover only the mostly used functions.
Hello Readers,
This post is the second post of the tri series articles on the Mathematical functions for Numpy Arrays.We are going to take a look at some mathematical functions which can be used with numpy arrays. Also these functions will be very helpful while doing some common mathematical operations.
Following is the list of functions which we are going to take a look at:
1 .max
2. argmax
3. clip
1. max
max() function is used to find the maximum between the given value.
The syntax to use the max() function is given by arr_ref.max(), where arr_ref is a numpy array.
Following code snippet shows the same:
Referring the code snippet above we know that the maximum value of all the specified value is 19 and we can also find the maximum value for each row by specifying the axis value. When we specified the axis value as 1 we get the maximum value along each row.
2.argmax
Earlier we had used the max() function which helps to find out the maximum value between the specified values.But what if we want to get the index of the maximum value, we can then use the argmax function.The syntax for using the argmax() function is arr_ref.argmax() where arr_ref is a numpy array.
From the above code snippet it can be seen that when we pass axis=0 to the argmax function we can we find the index of the maximum value along the vertical axis and when we specify axis=1 we find the maximum value along the horizontal axis. Both of the result can be verified from the snippet above which has an array of the dimension 5x4.
3.clip
If we want to limit the values within the numpy array within range like the numbers should be between 5 and 7 only then we can use the clip function.The syntax for using the clip() function is arr_ref.clip(start_value,end_value).
From the above code snippet it can be learnt that before using the clip function the values were in the range from 0 to 19. But using clip() function in the next step we limited the values within a specific range of 5 to 7.
Thank you.
That's all for this post!!
Thank you for reading this post.
If you have any suggestions regarding the post contents or if you need some more details on any other topic, please post it in the comments section.
Your suggestions are too valuable so they should not be missed.
1. max
max() function is used to find the maximum between the given value.
The syntax to use the max() function is given by arr_ref.max(), where arr_ref is a numpy array.
Following code snippet shows the same:
Referring the code snippet above we know that the maximum value of all the specified value is 19 and we can also find the maximum value for each row by specifying the axis value. When we specified the axis value as 1 we get the maximum value along each row.
2.argmax
Earlier we had used the max() function which helps to find out the maximum value between the specified values.But what if we want to get the index of the maximum value, we can then use the argmax function.The syntax for using the argmax() function is arr_ref.argmax() where arr_ref is a numpy array.
3.clip
If we want to limit the values within the numpy array within range like the numbers should be between 5 and 7 only then we can use the clip function.The syntax for using the clip() function is arr_ref.clip(start_value,end_value).
From the above code snippet it can be learnt that before using the clip function the values were in the range from 0 to 19. But using clip() function in the next step we limited the values within a specific range of 5 to 7.
Thank you.
That's all for this post!!
Thank you for reading this post.
If you have any suggestions regarding the post contents or if you need some more details on any other topic, please post it in the comments section.
Your suggestions are too valuable so they should not be missed.
Comments
Post a Comment