numpy fromstring空字符串分隔符

use*_*747 1 python string numpy

当我打电话时:

np.fromstring('3 3 3 0', sep=' ')
Run Code Online (Sandbox Code Playgroud)

它返回

array([ 3.,  3.,  3.,  0.])
Run Code Online (Sandbox Code Playgroud)

由于默认为,sep=''我希望以下调用返回相同的结果:

np.fromstring('3330')
Run Code Online (Sandbox Code Playgroud)

但是它引起了

ValueError: string size must be a multiple of element size
Run Code Online (Sandbox Code Playgroud)

为什么是这样?什么是得到的最Python的方式array([ 3., 3., 3., 0.])'3330'

And*_*den 5

您可以使用np.fromiter

In [11]: np.fromiter('3300', dtype=np.float64)
Out[11]: array([ 3.,  3.,  0.,  0.])

In [12]: np.fromiter('3300', dtype=np.float64, count=4)  # count=len(..)
Out[12]: array([ 3.,  3.,  0.,  0.])
Run Code Online (Sandbox Code Playgroud)