I have a matrix
import numpy as np
matrix = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]])
And I want to represent a discrete 2D physical space on cartesian coordinates with it. So for example, when accessing the values I'd get matrix[0,0] = 7, matrix[1,2] = 6, matrix[3,3] = 3.
How can I accomplish that? I have tried using np.meshgrid, but as far as I have managed to implement it, the results are not what I am looking for. What I'm looking for could be accomplished by transposing the matrix every time I try to access a value, but I would like a way to just change the indexing of the matrix directly.
Thanks!
You can use a view of your matrix with
np.flip:Usage:
You can also use
np.pad:Usage:
You can also Subclassing ndarray and override
__getitem__and__setitem__methods.