I have a string like mystr = \"100110\" (the real size is much bigger) I want to convert it to numpy array like mynumpy = [1, 0, 0, 1, 1, 0], mynumpy.shap
You could read them as ASCII characters then subtract 48 (the ASCII value of 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 could convert the string to a list of integers first:
>>> np.array(map(int, "100110"))
array([1, 0, 0, 1, 1, 0])
Edit: I did some quick timing and the first method is over 100x faster than converting it to a list first.