PY3:
In [62]: np.frombuffer('hello world')
...
AttributeError: 'str' object has no attribute '__buffer__'
In [63]: np.frombuffer(b'hello world')
...
ValueError: buffer size must be a multiple of element size
In [64]: np.frombuffer(b'hello world',dtype='S1')
Out[64]:
array([b'h', b'e', b'l', b'l', b'o', b' ', b'w', b'o', b'r', b'l', b'd'], dtype='|S1')
PY3 - unicode. b .
np.frombuffer , . 'hello world' PY2 PY3 .
, SO frombuffer, , . np.array , :
In [80]: np.array('hello')
Out[80]:
array('hello',
dtype='<U5')
list, :
In [81]: np.array(list('hello'))
Out[81]:
array(['h', 'e', 'l', 'l', 'o'],
dtype='<U1')
In [82]: np.array(b'hello')
Out[82]:
array(b'hello',
dtype='|S5')
In [83]: np.array(list(b'hello'))
Out[83]: array([104, 101, 108, 108, 111])
In [85]: np.fromiter('hello','S1')
Out[85]:
array([b'h', b'e', b'l', b'l', b'o'],
dtype='|S1')
In [86]: np.fromiter('hello','U1')
Out[86]:
array(['h', 'e', 'l', 'l', 'o'],
dtype='<U1')*
: https://github.com/numpy/numpy/issues/8933