Ask Your Question
1

Matrix with negative indices

asked 2022-07-25 15:15:11 +0200

jesuslop gravatar image

Is there a way or hack to operate with matrices with negative indices? For example a 3x3 matrix with row indices {-1,0,1} and column indices {-1, 0, 1}. So one can do m[-1,-1] for first row and column entry, while still retain matrix operations (ring ops, determinant, etc.). I'm dealing with random walks where the symetry needs that.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2022-07-25 15:27:43 +0200

slelievre gravatar image

Python uses negative indices to index from the end.

So for a 3 by 3 matrix, you can think of the indices as 0, 1, 2 or equivalently -3, -2, -1.

In other words you could also think of them as 0, 1, -1.

sage: m = matrix(3, [1 .. 9])
sage: m
[1 2 3]
[4 5 6]
[7 8 9]
sage: m[-1, -1]
9
sage: m[-1, 1]
8
sage: m[1, -1]
6
edit flag offensive delete link more

Comments

ok thanks for chiming in fast, but I'd welcome a more direct representation if there's one. The python convention seems to obscure my reasoning about matrices.

jesuslop gravatar imagejesuslop ( 2022-07-25 18:09:15 +0200 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2022-07-25 15:15:11 +0200

Seen: 190 times

Last updated: Jul 25 '22