mirror of
https://github.com/rasbt/python_reference.git
synced 2024-11-23 20:11:13 +00:00
make bitstring func
This commit is contained in:
parent
fd65f8598f
commit
01fbbeb69c
14
howtos_as_py_files/make_bitstring.py
Normal file
14
howtos_as_py_files/make_bitstring.py
Normal file
|
@ -0,0 +1,14 @@
|
|||
# Generating a bitstring from a Python list or numpy array
|
||||
# where all postive values -> 1
|
||||
# all negative values -> 0
|
||||
|
||||
def make_bitstring(ary)
|
||||
return np.where(ary > 0, 1, 0)
|
||||
|
||||
|
||||
### Example:
|
||||
|
||||
ary1 = np.array([1, 2, 0.3, -1, -2])
|
||||
make_bitstring(ary1)
|
||||
|
||||
# returns array([1, 1, 1, 0, 0])
|
Loading…
Reference in New Issue
Block a user