
Jan. 25, 2012
3:12 p.m.
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.