Skip to content

Commit 01fbbeb

Browse files
committed
make bitstring func
1 parent fd65f85 commit 01fbbeb

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Generating a bitstring from a Python list or numpy array
2+
# where all postive values -> 1
3+
# all negative values -> 0
4+
5+
def make_bitstring(ary)
6+
return np.where(ary > 0, 1, 0)
7+
8+
9+
### Example:
10+
11+
ary1 = np.array([1, 2, 0.3, -1, -2])
12+
make_bitstring(ary1)
13+
14+
# returns array([1, 1, 1, 0, 0])

0 commit comments

Comments
 (0)