[Numpy-discussion] Permuting sparse arrays

Edward C. Jones edcjones@comcast....
Wed Jan 25 09:12:23 CST 2012


I have a vector of bits where there are many more zeros than one.  I 
store the array as a sorted list of the indexes where the bit is one.  
If the bit array is (0, 1, 0, 0, 0, 1, 1), it is stored as (1, 5, 6).  
If the bit array, b, has length n, and p is a random permutation of 
arange(n), then I can permute the bit array using fancy indexing: b[p].  
Is there some neat trick I can use to permute an array while leaving it 
in the list-of-indexes form?  Currently I am doing it with a Python loop 
but I am looking for a faster way.


More information about the NumPy-Discussion mailing list