用NumPy数组索引列表时出现TypeError:只有整数标量数组才能转换为标量索引

2024-10-01 07:24:15 发布

您现在位置:Python中文网/ 问答频道 /正文

以下代码:

x = list(range(0,10))
random.shuffle(x)
ind = np.argsort(x)
x[ind]

产生错误:TypeError:只有整数标量数组才能转换为标量索引

请注意,我的问题与问题不同, “numpy array TypeError: only integer scalar arrays can be converted to a scalar index”,这是在尝试更复杂的东西。

我在这个问题上的错误是,我试图在一个普通的python列表上使用一个索引列表——请看我的答案。我希望它发生的范围远不止使用range和shuffle。


Tags: 代码列表错误nprange整数random数组