D0SBoots - 1 year ago 123

Python Question

numpy.unravel_index() takes a shape and a flat index into an array, and returns the tuple that represents that index in the array. Is there an inverse? I can compute it by hand, but this seems like it must be a built-in function somewhere...

Answer Source

The answer lies in numpy.ndarray.strides. See http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.strides.html