>> I've got a few questions that came up as I tried to calculate various >> statistics about an image time-series. For example, I have an array >> of shape (t,x,y) representing t frames of a time-lapse of resolution >> (x,y). >> >> Now, say I want to both argsort and sort this time-series, pixel- >> wise. (For example.) >> >> In 1-d it's easy: >> indices = a.argsort() >> sorted = a[indices] >> >> I would have thought that doing this on my 3-d array would work >> similarly: >> indices = a.argsort(axis=0) >> sorted = a.take(indices, axis=0) >> >> Unfortunately, this gives a ValueError of "dimensions too large." >> Now, I know that 'a.sort(axis=0)' works fine for the given example, >> but I'm curious about how to this sort of indexing operation in the >> general case. > > Unfortunately, argsort doesn't work transparently with take or > fancy indexing for multidimensional arrays. I am thinking of adding > a function argtake for this, and also for the results returned by > argmax and argmin, but at the moment you have to fill in the > values of the other indices and use fancy indexing. For now, it is > probably simpler, prettier, and faster to just sort the array.
Thanks Charles. Unfortunately, the argsort/sort buisness was, as I mentioned, just an example of the kind of 'take' operation that I am trying to figure out how to do. There are other operations that will have similarly-formatted 'indices' arrays (as above) that aren't generated from argsort... As such, how do I "fill in the values of the other indices and use fancy indexing"? Even after reading the numpy book about that, and reading the docstring for numpy.take, I'm still vague on this. Would I use numpy.indices to get a list of index arrays, and then swap in (at the correct position in this list) the result of argsort (or the other operations), and use that for fancy indexing? Is there an easier/faster way? Thanks again, Zach _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion