Converting string to numpy array
Given a string abcxyz
, I want it to return a numpy array like:
array(["a", "b", "c", "x", "y", "z"]).
I have tried fromstring
Bingrid = np.fromstring(elements, dtype=str)
but it returns
ValueError: Zero-valued itemsize.
Use list()
.
import numpy as np
s = "abcxyz"
print(np.array(list(s)))
Output:
['a' 'b' 'c' 'x' 'y' 'z']
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments