Skip to content Skip to sidebar Skip to footer

Corresponding Coordinates Of A Vectorized Matrix In Python

I had already an answer here of how to get using Matlab the corresponding coordinates of a vectorized matrix. I am wondering how can the answer be changed to Python. Does Python ap

Solution 1:

Numpy arrays are stored in row-major order so you would need

col = np.mod(i,m)
row = np.floor((i)/m)

which can be written simpler as

col = i%m
row = i//m

However, numpy has the numpy.unravel_index function which does this without the need for manual computations.

Post a Comment for "Corresponding Coordinates Of A Vectorized Matrix In Python"