Python:用另一个数组的元素作为键对数组进行排序?

2024-04-18 23:56:18 发布

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

import numpy as np
x = np.array(range(10 * 30)).reshape(100, 3)
y = np.array(range(1010, 10, -10))
res = sorted(x, key = lambda y:y) #ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
res = sorted(x, key=y) #TypeError: 'tuple' object is not callable

Tags: thelambdakeyimportnumpyisasnp