D0SBoots - 8 months ago 84

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

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

Source (Stackoverflow)