代码记录

Python3找出List中最大/最小的N个数及索引

# -*- coding: utf-8 -*-
import heapq
nums = [1, 8, 2, 23, 7, -4, 18, 23, 24, 37, 2]
# 最大的3个数的索引
max_num_index_list = map(nums.index, heapq.nlargest(3, nums))
# 最大的3个数的索引
max_num_index_list = map(nums.index, heapq.nlargest(3, nums))
print(list(max_num_index_list))
print(list(min_num_index_list))

你可能感兴趣的:(机器学习,Tensor)