Calculate the difference between the maximum and the minimum values of a given NumPy array along the second axis Last Updated : 15 Jul, 2025 Comments Improve Suggest changes 1 Likes 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] Create Quiz Comment Y ysachin2314 Follow 1 Improve Y ysachin2314 Follow 1 Improve Article Tags : Python Python-numpy Python numpy-program Python numpy-Linear Algebra Explore Python FundamentalsPython Introduction 2 min read Input and Output in Python 4 min read Python Variables 4 min read Python Operators 4 min read Python Keywords 2 min read Python Data Types 8 min read Conditional Statements in Python 3 min read Loops in Python - For, While and Nested Loops 5 min read Python Functions 5 min read Recursion in Python 4 min read Python Lambda Functions 5 min read Python Data StructuresPython String 5 min read Python Lists 4 min read Python Tuples 4 min read Python Dictionary 3 min read Python Sets 6 min read Python Arrays 7 min read List Comprehension in Python 4 min read Advanced PythonPython OOP Concepts 11 min read Python Exception Handling 5 min read File Handling in Python 4 min read Python Database Tutorial 4 min read Python MongoDB Tutorial 3 min read Python MySQL 9 min read Python Packages 10 min read Python Modules 3 min read Python DSA Libraries 15 min read List of Python GUI Library and Packages 3 min read Data Science with PythonNumPy Tutorial - Python Library 3 min read Pandas Tutorial 4 min read Matplotlib Tutorial 5 min read Python Seaborn Tutorial 3 min read StatsModel Library - Tutorial 3 min read Learning Model Building in Scikit-learn 6 min read TensorFlow Tutorial 2 min read PyTorch Tutorial 6 min read Web Development with PythonFlask Tutorial 8 min read Django Tutorial | Learn Django Framework 7 min read Django ORM - Inserting, Updating & Deleting Data 4 min read Templating With Jinja2 in Flask 6 min read Django Templates 5 min read Build a REST API using Flask - Python 3 min read Building a Simple API with Django REST Framework 3 min read Python PracticePython Quiz 1 min read Python Coding Practice 1 min read Python Interview Questions and Answers 15+ min read Like