Question: Please solve this Python question Question - 01 Given a 2D array of size (m, n) sort all the diagonal elements of the array. Write

Please solve this Python question Question - 01 Given a 2D arrayPlease solve this Python question

Question - 01 Given a 2D array of size (m, n) sort all the diagonal elements of the array. Write a function that will take the array and a boolean as input and provide the sorted array as output. The default value for boolen is True. If set to False, sort the anti-diagonal elements For example, input = [[1,2,3], [4,0,1], [9,3,10]] output= [[0,1,3], (3,1,2], [9,4,10]] main diagonal elements are = 1,0,10 diag 1 elements are = 2,1 diag 2 elements are = 3 diag -1 elements are = 4,3 diag -2 elements are = 9 --- sorted as - > 0,1,10 sorted as -> 1,2 sorted as -> 3 --- sorted as -> 3,4 --- sorted as -> 9 def ques_01 (arr, diag=True): return # run this cell to check your output. Don't modify this cell arr= [[1,2,3], [4,0,1], [9,3,10]] out= [[0,1,3], (3,1,2], [9,4,10]] ques_01 (arr, diag=True) ==out

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!