diff --git a/howtos_as_py_files/make_bitstring.py b/howtos_as_py_files/make_bitstring.py new file mode 100644 index 0000000..fc2baa4 --- /dev/null +++ b/howtos_as_py_files/make_bitstring.py @@ -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]) \ No newline at end of file