需求
我有个数组,我想找从小到大排序的第90%个值,python示例
思路
如果你想找到数组中从小到大排序的第90%个位置的值,你可以先对数组进行排序,然后找到对应位置的值。以下是一个例子:
import numpy as np
# 假设你的数组是:
array = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
# 对数组进行排序
sorted_array = np.sort(array)
# 计算90%位置的索引
index = int(len(sorted_array) * 0.9)
# 找到对应位置的值
value = sorted_array[index]
print(value)
这将打印出数组中从小到大排序的第90%个位置的值。在这个例子中,value将会是9。