Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Transforming a matrix by placing its elements in the reverse order of the initial in python

im looking to solve the problem mentioned in the title without any specific functions that may or may not exist for this[Example]. Something along the lines of using mostly loops.

I tought about reversing each individual row using list.reverse() and then moving the rows around but im not sure how to implement it.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

try this new realization and this will not change the original Matrix

Matrix = [[1,2,3],[4,5,6],[7,8,9]]
newMatrix = []
for line in range(len(Matrix)):
    newMatrix.append(sorted(Matrix[line],reverse=True))

newMatrix.reverse()
print(newMatrix)
print(Matrix)

output:

[[9, 8, 7], [6, 5, 4], [3, 2, 1]]
[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading