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
Post a Comment