Let’s see how to calculate the difference between the maximum and the minimum values of a given NumPy array along the second axis. Here, the Second axis means row-wise.
So firstly for finding the row-wise maximum and minimum elements in a NumPy array we are using numpy.amax() and numpy.amin() functions of NumPy library respectively. then After that we simply perform subtraction on it.
numpy.amax(): This function returns maximum of an array or maximum along axis(if mentioned).
Syntax: numpy.amax(arr, axis = None, out = None, keepdims = )
numpy.amin(): This function returns minimum of an array or minimum along axis(if mentioned).
Syntax: numpy.amin(arr, axis = None, out = None, keepdims = )
Now, Let’s see an example:
given array: [[100 20 305] [200 40 300]] difference: [285 260]
original array: [[12 13 14 15 16] [17 18 19 20 21]] Difference: [4 4]
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.