import numpy as np
vector=np.array(['0','5','10'])
vector=vector.astype(float)
print(vector)
输出
[ 0. 5. 10.]
vector=np.array(['0','5','10','a'])
vector=vector.astype(float)
报错
ValueError Traceback (most recent call last)
in
----> 1 vector=vector.astype(float)
ValueError: could not convert string to float: 'a'