gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 11:35:21 26 4
gpt4 key购买 nike

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

最佳答案

尝试参数排序:

import numpy as np
x = np.array(range(10 * 30)).reshape(100, 3)
y = np.array(range(1010, 10, -10))
args = y.argsort(axis = 0)
print x[args]

关于Python:使用另一个数组的元素作为键对数组进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5128787/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com