小编Vik*_*wal的帖子

Python:如何在Windows资源管理器上打开文件夹(Python 3.6.2,Windows 10)

如果我将要打开的路径存储在一个名为finalpath的字符串中,它看起来像这样:"./ 2.8电影/英文/ Die Hard Series"

那么如何在Windows资源管理器中打开它?(Windows 10)(Python 3.6.2)

PS我知道很多人都问过这个问题,但我没有发现它们.请尽快回答.

windows operating-system windows-explorer python-3.x windows-10

6
推荐指数
3
解决办法
1万
查看次数

查找二维数组中最高元素的列表:Python 3

我有一个大小为(640X480)的二维数组,如下所示:

[[1.2 , 9.5 , 4.8 , 1.7],
 [5.5 , 8.1 , 7.6 , 7.1],
 [1.4 , 6.9 , 7.8 , 2.2]]     (this is a sample of a 4X3 array)
Run Code Online (Sandbox Code Playgroud)

我必须以最快的方式找到数组中的前 100(或 N)个最高值;所以我需要最优化的代码,它需要最少的处理时间。

因为它是一个巨大的数组,所以如果我只检查每 2 个元素或每 3 或 4 个元素就可以了。

算法的输出应该是一个元组列表,每个元组都是高值元素的二维索引。

例如 9.5 的索引将是 (0,1)

我找到了一个解决方案,但它太慢了:

indexes=[]
for i in range(100):
    highest=-1
    highindex=0.1
    for indi,i in enumerate(array):
        for indj,j in enumerate(i):
            if j>highest and not((indi,indj) in indexes):
                highest= j
                highindex=(indi,indj)
    indexes.append(highindex)
Run Code Online (Sandbox Code Playgroud)

python arrays optimization search numpy

2
推荐指数
1
解决办法
969
查看次数