Calculate the difference between the maximum and the minimum values of a given NumPy array along the second axis Last Updated : 02 Sep, 2020 Summarize Comments Improve Suggest changes Share Like Article Like Report 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: Example 1: Python3 # import library import numpy as np # create a numpy 2d-array x = np.array([[100, 20, 305], [ 200, 40, 300]]) print("given array:\n", x) # get maximum element row # wise from numpy array max1 = np.amax(x ,1) # get minimum element row # wise from numpy array min1 = np.amin(x, 1) # print the row-wise max # and min difference print("difference:\n", max1 - min1) Output: given array: [[100 20 305] [200 40 300]] difference: [285 260] Example 2: Python3 # import library import numpy as np # list x = [12, 13, 14, 15, 16] y = [17, 18, 19, 20, 21] # create a numpy 2d-array array = np.array([x, y]).reshape((2, 5)) print("original array:\n", array) # find max and min elements # row-wise max1, min1 = np.amax(array, 1), np.amin(array,1) # print the row-wise max # and min difference print("Difference:\n", max1 - min1) Output: original array: [[12 13 14 15 16] [17 18 19 20 21]] Difference: [4 4] Comment More infoAdvertise with us Next Article Calculate the difference between the maximum and the minimum values of a given NumPy array along the second axis Y ysachin2314 Follow Improve Article Tags : Python Python-numpy Python numpy-program Python numpy-Linear Algebra Practice Tags : python Similar Reads Find the maximum and minimum element in a NumPy array An array can be considered as a container with the same types of elements. Python has its array module named array. We can simply import the module and create our array. But this module has some of its drawbacks. The main disadvantage is we can't create a multidimensional array. And the data type mu 4 min read How to get the floor, ceiling and truncated values of the elements of a numpy array? In this article, let's discuss how to get the floor, ceiling, and truncated values of the elements of a Numpy array. First, we need to import the NumPy library to use all the functions available in it. This can be done with this import statement: import numpy as np Getting the floor value The greate 3 min read NumPy: How to Calculate the Difference Between Neighboring Elements in Array To calculate the difference between neighboring elements in an array using the NumPy library we use numpy.diff() method of NumPy library. It is used to find the n-th discrete difference along the given axis. The first output is given by: difference[i] = a[i+1] - a[i]Example:Python NumPy program to c 2 min read How to normalize an NumPy array so the values range exactly between 0 and 1? In this article, we will cover how to normalize a NumPy array so the values range exactly between 0 and 1. Normalization is done on the data to transform the data to appear on the same scale across all the records. After normalization, The minimum value in the data will be normalized to 0 and the ma 3 min read Return the maximum of an array or maximum ignoring any NaNs in Python In this article, we will cover how to return the maximum of an array or maximum by ignoring any NaNs in Python using NumPy. ExampleInput: [ -1. -2. nan 1000.] Output: 1000.0 Explanation: maximum value of the array ignoring nans. One approach to use the built-in Python function max(), along with the 3 min read Like