You can read them as ASCII characters and then subtract 48 (ASCII value 0 ). This should be the fastest way for large strings.
>>> np.fromstring("100110", np.int8) - 48 array([1, 0, 0, 1, 1, 0], dtype=int8)
Alternatively, you can first convert the string to a list of integers:
>>> np.array(map(int, "100110")) array([1, 0, 0, 1, 1, 0])
Change I did some quick calculations, and the first method is more than 100 times faster than converting it to a list.
source share