解决问题:only integer scalar arrays can be converted to a scalar index
Posted yuanfeni
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决问题:only integer scalar arrays can be converted to a scalar index相关的知识,希望对你有一定的参考价值。
import numpy as np
imput=[[1,2],[3,4],[5,6],[7,0]]
shuff_args=np.arange(4)
np.random.shuffle(shuff_args)
imput_tra=imput[shuff_args]
print(imput_tra)
报错:TypeError: only integer scalar arrays can be converted to a scalar index
类型错误:只有整数标量数组才能转换为标量索引。此问题出现在最新的python、numpy版本中
改为以下代码:
imput=[[1,2],[3,4],[5,6],[7,0]]
shuff_args=np.arange(4)
np.random.shuffle(shuff_args)
imput_tra=np.array(imput)[shuff_args]
print(imput_tra)
输出结果:[[7 0] [5 6] [1 2] [3 4]]
解决问题
以上是关于解决问题: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 integers, slices (`:`), ellipsis (`...`), tf.newaxis (`None`) and scalar tf.int32/tf
成功解决TypeError: only size-1 arrays can be converted to Python scalars
(已解决)多卡训练时报错RuntimeError: grad can be implicitly created only for scalar outputs