1
A
回答
0
您可以使用np.argsort
,如@NPE here所做的那样。以下是两个较小阵列的示例:
def nlargest_cols(a, n):
return a[:, sorted(a.sum(axis=0).argsort()[-n:][::-1])]
# `a` is a 3x4 array with column sums getting
# larger from left to right.
a = np.arange(12).reshape(3,4)
# `b` is `a` rotated 2 turns.
b = np.rot90(a, 2)
print(nlargest_cols(a, 2))
# [[ 2 3]
# [ 6 7]
# [10 11]]
print(nlargest_cols(b, 3))
# [[11 10 9]
# [ 7 6 5]
# [ 3 2 1]]
相关问题
- 1. 提取3d numpy数组的某些列
- 2. 从numpy距离数组中提取N个最接近的对
- 3. 如何从排列的numpy数组中提取数组?
- 4. Python:提取字典中的数据列表numpy数组
- 5. 从时间序列数据框的列中提取最高值
- 6. 高效地分割一列numpy数组
- 7. 生成n×n的数组中numpy的
- 8. 提取Python中列表中的N维数组的元素
- 9. numpy数组中的最小提取指数
- 10. 传递列表作为切片中的N维数组numpy的
- 11. 从numpy数组中提取数据
- 12. 如何从数据框中为列的子集高效地获取numpy数组?
- 13. 对象数组,提取最高值
- 14. 在组中找到最高分并更新基于n的列
- 15. 我需要在Numpy数组中的N个最小(索引)值
- 16. 蟒提取n列
- 17. 提取一个numpy的列
- 18. 在numpy数组中比较多列
- 19. 如何从numpy数组列表中删除一个numpy数组?
- 20. 从列表中提取数据 - 查找最高值
- 21. 从numpy数组中提取X坐标
- 22. SQL查询从列表中获得最高的“n”分数
- 23. 按列解压NumPy数组
- 24. 展平NumPy数组列表?
- 25. 如何在numpy数组列中查找最大值?
- 26. Python中3x1 numpy数组的列表
- 27. Python中的列表和Numpy数组
- 28. 检查numpy数组中的不变列
- 29. 2D块系列的3D数组在numpy
- 30. numpy广播(N,)和与(N,1)数组