TypeError: only integer scalar arrays can be converted to a scalar index

TypeError: only integer scalar arrays can be converted to a scalar index

numpy.shape函数报错

TypeError: 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 integer scalar arrays can be converted to a scalar index
字面意思是:只有整数标量数组才能转换成标量索引。

解决方法

TypeError: only integer scalar arrays can be converted to a scalar index
此处改为一个准确的数字就不报错了,主要原因是自己粗心,居然出现了变量命名重复的错误。导致变成了一个ndarray。
从其他博客上看,出现这个问题的原因也可能是因为此处的变量不被认为是一个整数。