![](/img/trans.png)
[英]How to get the fatest way of getting the maximum values element-wised of "n" matrices in Python/Numpy?
[英]How to efficiently find separately for each element N maximum values among multiple matrices?
評論建議使用np.partition
function。 我用 cupy 替換了numpy的使用,它使用了 GPU。 並且還添加了一個緩沖區來減少排序頻率。
import cupy as np
buf = // # As much as fits into the GPU
largests = np.zeros((buf + N, h, w))
for i in range(num):
val = //
largests[i % buf] = val
if i % buf == buf - 1:
largests.partition(range(buf, buf + N), axis=0)
largests.partition(range(buf, buf + N), axis=0) # Let's not forget the tail
res = largests[:-(N + 1):-1]
該解決方案的工作速度不是很快,但我已經接受了這種速度。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.