numpy使用fromstring实验数据分析

# -*- coding: utf-8 -*-
import numpy as np
s = "11011011011011011011011011011011"
print(len(s))
np.fromstring(s,dtype=np.int8)

输出如下:

32
array([49, 49, 48, 49, 49, 48, 49, 49, 48, 49, 49, 48, 49, 49, 48, 49, 49,
       48, 49, 49, 48, 49, 49, 48, 49, 49, 48, 49, 49, 48, 49, 49],
      dtype=int8)

可见fromstring 把 s 字符串里的unicode编码转换为对应的十进制数值,1对应49,0对应48

# -*- coding: utf-8 -*-
import numpy as np
s = "11011011011011011011011011011011"
np.fromstring(s,dtype=np.int16)

输出如下:

array([12593, 12592, 12337, 12593, 12592, 12337, 12593, 12592, 12337,
       12593, 12592, 12337, 12593, 12592, 12337, 12593], dtype=int16)

猜你喜欢

转载自blog.csdn.net/sinat_28442665/article/details/86240004