![](/img/trans.png)
[英]Python import CSV into array TypeError: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe'
[英]Numpy.dot TypeError: Cannot cast array data from dtype('float64') to dtype('S32') according to the rule 'safe'
使用np.dot(a,bT)
时为什么会出现此错误:
TypeError: Cannot cast array data from dtype('float64')
to dtype('S32') according to the rule 'safe'
a和b的类型为numpy.ndarray
。 我的NumPy
版本是1.11.0。
只需从BrenBarn和Warren Weckesser那里获取输入,就可以提供一个应该运行的代码片段(通过将你的字符串转换为float):
a = map(lambda x: float(x),a)
b = map(lambda x: float(x),b)
np.dot(a,b.T)
或者@JLT建议的更简单
a = map(float,a)
b = map(float,b)
np.dot(a,b.T)
但正如Warren Weckesser所说,你应该检查数组的类型,很可能已经包含了浮点数。
尝试将整个numpy数组转换为float示例:
train = train.astype(float)
train_target = train_target.astype(float)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.