Click here to Skip to main content
15,666,183 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just came over from Stack Overflow after getting question banned, so I have no idea how you guys will like me, but here goes. I have a 16x16 matrix, and I'm trying to move the columns to the right.

What I have tried:

Here's how I have it right now:
m = # 16 x 16 matrix
for i in m:
    i[0], i[1], i[2], ... , i[14], i[15] = i[15], i[0], i[1], ... , i[13], i[14]

This just loops through all the rows and moves everything to the right. But, as you can see, it's really long. Is there a shorter way to do this? preferably without numpy, Thanks!
Updated 8-Feb-21 21:16pm
Gerry Schmitz 8-Feb-21 15:57pm    
Seems you'd be better of with 16 "lists" if you want to move them around ... then maybe convert to an array. I can see where someone could lose patience.

Also, it's irritating when the point could be made with a "smaller" example.
Captian Ahab 8-Feb-21 16:11pm    
Well... it's a list of 16 lists already, or do you mean something else?
Luc Pattyn 8-Feb-21 20:42pm    
Maybe the matrix could be organized as a collection/array of columns, rather than a collection/array of rows?

You might get a more tailored answer if you were to provide more context: what is the overall application about, what libraries or operations are involved, why would you want to move columns around, etc...

Richard MacCutchan 9-Feb-21 4:28am    
Two simple loops should do it, with index values for the row and column. The row index moving forwards from 0 to 15, and the column index backwards from 15 to 0.

1 solution

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900