Min-Max Matrix Z70247


Statement
 

pdf   zip   main.py

thehtml

Given a square matrix M of integers, with size n×n, n≥1, its matrix minMax is a matrix mM with size x×2 such that for all i, 0≤in, element mM[i][0] is the minimum element of the i-th row of M and mM[i][1] is the maximum element of the i-th column of M.

For instance, if M is the matrix

1 2 3
6 7 4
8 9 5

then mM will be:

1 8
4 9
5 5

Implement a function minMax(M) that given a square matrix M returns its minMax matrix.

You can use the python min and max functions to compute the maximum and minimum of a list.

Observation

Only the function is expected. Remember to comment out any testing main program you may have.

Sample session
>>> minMax([[1, 2, 3], [6, 7, 4], [8, 9, 5]])
[[1, 8], [4, 9], [5, 5]]
>>> minMax([[1, 2, 3], [3, 2, 1], [2, 3, 1]])
[[1, 3], [1, 3], [1, 3]]
>>> minMax([[100]])
[[100, 100]]
>>> minMax([[2, 10], [5, 1]])
[[2, 5], [1, 10]]
>>> minMax([[14, 4], [1, 1]])
[[4, 14], [1, 4]]
>>> minMax([[5, 2, 1, -2], [21, -1, -3, 8], [2, 3, 6, 6], [1, 2, 4, 5]])
[[-2, 21], [-3, 3], [2, 6], [1, 8]]
Information
Author
Lluís Padró
Language
English
Official solutions
Python
User solutions
Python