python报错:only integer scalar arrays can be converted to a scalar index
Posted _刘文凯_
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python报错:only integer scalar arrays can be converted to a scalar index相关的知识,希望对你有一定的参考价值。
如题,在使用python时出现错误:only integer scalar arrays can be converted to a scalar index ; 类似的错误都可以用这个方法解决 交叉验证时错误等
代码
for tr_idx, val_idx in kfold.split(x_train, y_train):
tr_X_tmp, val_X_tmp, tr_y, val_y = x_train[tr_idx], x_train[val_idx], y_train[tr_idx], y_train[val_idx]
...
原因:
数据类型不匹配
x_train, y_train 必须是numpy类型,而不能是list类型
解决:
类型转换
import numpy as np
x_train = np.array(x_train)
y_train = np.array(y_train)
for tr_idx, val_idx in kfold.split(x_train, y_train):
tr_X_tmp, val_X_tmp, tr_y, val_y = x_train[tr_idx], x_train[val_idx], y_train[tr_idx], y_train[val_idx]
...
...
以上是关于python报错:only integer scalar arrays can be converted to a scalar index的主要内容,如果未能解决你的问题,请参考以下文章
TypeError: only integer scalar arrays can be converted to a scalar index
TypeError: Only integers, slices (`:`), ellipsis (`...`), tf.newaxis (`None`) and scalar tf.int32/tf
python 使用 selenium 时,报错: This version of ChromeDriver only supports Chrome version 85
python 使用 selenium 时,报错: This version of ChromeDriver only supports Chrome version 85
python报错 TypeError: string indices must be integers
typeError:The value of a feed cannot be a tf.Tensor object.Acceptable feed values include Python sca