Question: Python-- (saddle points.py): Detect saddle points in a matrix. So say you have a matrix like so: 0 1 2 |--------- 0 | 9 8

Python--

(saddle points.py): Detect saddle points in a matrix. So say you have a matrix like so: 0 1 2 |--------- 0 | 9 8 7 1 | 5 3 2 <--- saddle point at (1,0) 2 | 6 6 7 It has a saddle point at (1, 0). Its called a saddle point because it is greater than or equal to every element in its row and less than or equal to every element in its column. A matrix may have zero or more saddle points. Your code should be able to provide the (possibly empty) list of all the saddle points for any given matrix. Note that you may find other definitions of matrix saddle points online, but the tests for this exercise follow the above unambiguous definition. Develop a function called saddle points that accepts a matrix argument. Matrix should be in the form of list of lists. Each list in the main list is a row in the matrix. This function should return a set that contains all the saddle points of the given matrix. Saddle points should be in defined as a tuple with two elements, with first element denoting the row index and the second denoting the column index. For example, calling saddle points([[6, 7, 8], [5, 5, 5], [7, 5, 6]]) should return {(1, 2), (1, 0), (1, 1)}.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!