python : array str to float

2019-12-03  本文已影响0人  夏天不热也不冷
import numpy as np
x = np.array(['1.1', '2.2', '3.3'])
y = x.astype(np.float)

如果遇到: ValueError: Can only create a chararray from string data.

x=[float(n) for n in x]
x=np.array(x)

参考网址: https://stackoverflow.com/questions/3877209/how-to-convert-an-array-of-strings-to-an-array-of-floats-in-numpy

上一篇下一篇

猜你喜欢

热点阅读