Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: masked slicing #190

Closed
arsserpentarium opened this issue Mar 4, 2023 · 6 comments
Closed

Feature: masked slicing #190

arsserpentarium opened this issue Mar 4, 2023 · 6 comments

Comments

@arsserpentarium
Copy link

arsserpentarium commented Mar 4, 2023

there is other quite similar feature suggestion,which is related to list indexing:
#156
However, I need a bit different thing. List indexing for bit retrieval:
`

a = bitarray('10010011')
lst = [1,0,1,0,1,1,1,1] #masking
a[lst]
bitarray('100011')
a[bitarray('10111000')]
bitarray('1101')
lst = [0,1,3,7] #indexing
a[lst]
bitarray('1011')
`

I'd be glad to see that functions in any implementation.

@ilanschnell
Copy link
Owner

Thanks for using bitarray! If I understand your example correctly, masking is simply the (already existing) & operator:

>>> a = bitarray('10010011')
>>> lst = [1,0,1,0,1,1,1,1] #masking
>>> a & bitarray(lst)  # you wrote a[lst] here
bitarray('10000011')

I'm having the same concerns as with #156 for adding the indexing with a list feature. So having bitarray.util.getitems() as well. If I get some time, I would implement both of these functions at once.

@arsserpentarium
Copy link
Author

nope. And operator can't compose bitarray from bits of sequence a, which are on places of 1 in b. Numpy can do such thing, but it's quite inconvenient to use numpy for binary processing.

It'll be fine if that feature would be implemented as function.

thank you for your library.

@ilanschnell
Copy link
Owner

#204 has now been merged which allows indexing by lists

@ilanschnell
Copy link
Owner

#205 has been merged which can now allows indexing by bitarrays as masks, see:
https://github.com/ilanschnell/bitarray/blob/master/doc/indexing.rst#masked-indexing

@addandaum
Copy link

Oh thank you very much.

@ilanschnell
Copy link
Owner

The new features (sequence and masked indexing) are now available in bitarray 2.8.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants