scipy - Numpy: convert index in one dimension into many dimensions -


many array methods return single index despite fact array multidimensional. example:

a = rand(2,3) z = a.argmax() 

for 2 dimensions, easy find matrix indices of maximum element:

a[z/3, z%3] 

but more dimensions, can become annoying. numpy/scipy have simple way of returning indices in multiple dimensions given index in 1 (collapsed) dimension? thanks.

got it!

a = x.argmax() (i,j) = unravel_index(a, x.shape) 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -