Challenge: Find Min and Max from a 2-D NumPy Array

In this challenge, the minimum and maximum values need to be returned for each row of a 2-D Numpy array.

We'll cover the following

Problem statement

The function getMinMax(arr) needs to be implemented. The arr is the multidimensional array on which operations are performed. The dimensions of the NumPy array are random, i.e., the number of rows and columns are not fixed. The elements of the array are also random. The task is to find the minimum and maximum value for each row of the multidimensional NumPy array and return all of them in a list.


The input to the function is a multidimensional array with random dimensions and data. The following is an example of how the input array should look.

[-3, 0, 5, -6]
[7, 2, -1, 9]
[12, -4, 3, 1]


The output is a list containing the minimum and maximum element from each row. First, the minimum element from each row should be stored, followed by the maximum element. The list should then be returned. The following is an example of what the output of the above input array should look like.

[-6, 5, -1, 9, -4, 12]

Coding exercise

Write your code below. It is recommended​ that you try solving the exercise yourself before viewing the solution.

Get hands-on with 1000+ tech skills courses.