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

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

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