First time here? Check out the FAQ!

Ask Your Question
1

Matrix with negative indices

asked 2 years ago

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.

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
1

answered 2 years ago

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
Preview: (hide)
link

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 ( 2 years ago )

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: 2 years ago

Seen: 352 times

Last updated: Jul 25 '22