[Numpy-discussion] In-place fancy selection

Charles R Harris charlesr.harris@gmail....
Thu Mar 1 14:40:58 CST 2007


On 3/1/07, Francesc Altet <faltet@carabos.com> wrote:
>
> Hi,
>
> I don't think there is a solution for this, but perhaps anybody may
> offer some idea. Given:
>
> In [79]:a=numpy.arange(9,-1,-1)
> In [80]:b=numpy.arange(10)
> In [81]:numpy.random.shuffle(b)
> In [82]:b
> Out[82]:array([2, 6, 3, 5, 4, 9, 0, 8, 7, 1])
> In [83]:a=a[b]
> In [84]:a
> Out[84]:array([7, 3, 6, 4, 5, 0, 9, 1, 2, 8])
>
> is there a way to make the step 83 without having to keep 3 arrays
> in-memory at the same time? This is, some way of doing fancy indexing,
> but changing the elements *inplace*. The idea is to keep memory
> requeriments as low as possible when a and b are large arrays.
>
> Thanks!


You can also put the arrays together and implement it as an inplace sort,
which will save space at the price of n*log(n) operations. The idea is to
sort on the shuffled array while carrying the corresponding elements of the
other array along in the exchanges, which I think you can now do using
fields and the order keyword in the sort.
Chuck
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://projects.scipy.org/pipermail/numpy-discussion/attachments/20070301/0c64161c/attachment.html 


More information about the Numpy-discussion mailing list