Res.shape[0] Concept

I didn’t understand the concept behind res.shape[0] in the solution. Please guide me further to understand it.

I think you mean arr.shape[0] as there is no res.shape[0] in the code.

arr.shape returns the dimensions (rows, columns) of a 2-D array. As there are 5 rows and 5 columns in arr hence:

  1. arr.shape will return (5,5)
  2. arr.shape[0] will return 5

The question wants us to find the min and max from each array (each row) inside the 2d array. So to traverse through each array we use the number of rows (arr.shape[0]) in the for loop.

Hope this clears the confusion.