Ask Your Question
4

reverse a matrix

asked 2015-02-24 15:30:07 +0100

NONAME gravatar image

updated 2015-09-02 12:32:28 +0100

FrédéricC gravatar image

We can count backwards to flip a matrix A upside down with

sage: A[::-1,:]=A; A

Can we do it from left to right; I mean, for the matrix A=

[ 3  2 -5  0]
[ 1 -1  1 -4]
[ 1  0  1 -3]

Is there an easy way to obtain the following matrix

[ 0 -5  2  3]
[-4  1 -1  1]
[ 3  1  0  1]
edit retag flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
2

answered 2015-02-24 17:12:57 +0100

Well, you could use the matrix_from_columns method:

sage: A = matrix(3, 3, range(9))
sage: A
[0 1 2]
[3 4 5]
[6 7 8]
sage: A.matrix_from_columns(range(2,-1,-1))
[2 1 0]
[5 4 3]
[8 7 6]

Or you could take the transpose, use your idea to flip upside down, and then take another transpose:

sage: A.transpose()[::-1,:].transpose()
[2 1 0]
[5 4 3]
[8 7 6]
edit flag offensive delete link more
2

answered 2015-02-25 11:04:44 +0100

slelievre gravatar image

updated 2015-02-25 11:09:15 +0100

You're almost there!

sage: a = matrix(3, 3, range(9))
sage: b = a[::-1,:]      # reverse lines
sage: c = a[:,::-1]      # reverse columns
sage: d = a[::-1,::-1]   # reverse both
sage: a, b, c, d
(
[0 1 2]  [6 7 8]  [2 1 0]  [8 7 6]
[3 4 5]  [3 4 5]  [5 4 3]  [5 4 3]
[6 7 8], [0 1 2], [8 7 6], [2 1 0]
)
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2015-02-24 15:30:07 +0100

Seen: 1,583 times

Last updated: Feb 25 '15