Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
获取numpy.fromstring中的错误_Numpy - Fatal编程技术网

获取numpy.fromstring中的错误

获取numpy.fromstring中的错误,numpy,Numpy,我试图在不改变原始字符串“w”的含义的情况下,转换带有空格的字符串“w” import numpy as np w="\x01\x02 \x01\x02" results = np.fromstring(w, dtype=np.int16) print results 我收到的错误消息如下: > File "prj1.py", line 7, in <module> > results = np.fromstring(w, dtype=np.int16) > V

我试图在不改变原始字符串“w”的含义的情况下,转换带有空格的字符串“w”

import numpy as np
w="\x01\x02 \x01\x02"
results = np.fromstring(w, dtype=np.int16)
print results
我收到的错误消息如下:

> File "prj1.py", line 7, in <module> 
> results = np.fromstring(w, dtype=np.int16)
> ValueError: string size must be a multiple of element size
>文件“prj1.py”,第7行,在
>结果=np.fromstring(w,dtype=np.int16)
>ValueError:字符串大小必须是元素大小的倍数

有没有正确的转换方法?

np。二进制模式下的fromstring
不接受分隔符
w
如果没有空格,则可以工作。使用
np.int16
它尝试读取连续的2字节块作为数字。您有5个字节的空间。@hpaulj-谢谢。但是有没有办法将这个字符串转换成np.int16?删除空格?使用字符串方法应该很容易做到这一点。@hpaulj-是的,它起作用了!!谢谢:)