Ask Your Question
1

reverse a matrix

asked 2015-02-24 08:30:07 -0500

NONAME gravatar image

updated 2015-09-02 05:32:28 -0500

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
1

answered 2015-02-24 10:12:57 -0500

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
0

answered 2015-02-25 04:04:44 -0500

updated 2015-02-25 04:09:15 -0500

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 08:30:07 -0500

Seen: 107 times

Last updated: Feb 25 '15