Python:ufunc ‘subtract‘ did not contain a loop with signature matching types dtype(‘「U32‘)

python报错ufunc 'subtract' did not contain a loop with signature matching types dtype('

前面有个warning: FutureWarning: Beginning in version 0.22, arrays of bytes/strings will be converted to decimal numbers if dtype='numeric'. It is recommended that you convert the array to a float dtype before using it in scikit-learn, for example by using your_array = your_array.astype(np.float64).
  y_true = check_array(y_true, ensure_2d=False, dtype=dtype)

大概意思就是嫌弃我没有转换类型。

加入参数dtype = ‘float64’即可。

#Y = numpy.array(names_classes)
Y = numpy.array(names_classes, dtype = 'float64')

如果之前已经指定过dtype,可以用astype转化类型。

y = np.array([0, 1, 1], dtype='S32')
y = y.astype('float64')

参考:

https://blog.csdn.net/u012005313/article/details/51567804

你可能感兴趣的:(python)