mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-23 20:11:13 +00:00
bitstring
This commit is contained in:
parent
01fbbeb69c
commit
21e4d5e813
|
@ -6,9 +6,12 @@ def make_bitstring(ary)
|
|||
return np.where(ary > 0, 1, 0)
|
||||
|
||||
|
||||
def faster_bitstring(ary)
|
||||
return np.where(ary > 0).astype('i1')
|
||||
|
||||
### Example:
|
||||
|
||||
ary1 = np.array([1, 2, 0.3, -1, -2])
|
||||
make_bitstring(ary1)
|
||||
|
||||
# returns array([1, 1, 1, 0, 0])
|
||||
# returns array([1, 1, 1, 0, 0])
|
||||
|
|
Loading…
Reference in New Issue
Block a user