配列内のすべての要素のインデックスのリストを取得しようとしているので、1000 x 1000 の配列の場合、 [(0,0), (0,1),...,(999,999) になります。 ]。
これを行うための関数を作成しました。これは以下のとおりです。
def indices(alist):
results = []
ele = alist.size
counterx = 0
countery = 0
x = alist.shape[0]
y = alist.shape[1]
while counterx < x:
while countery < y:
results.append((counterx,countery))
countery += 1
counterx += 1
countery = 0
return results
時間を計った後、実行に約650ミリ秒かかっていたため、かなり遅いように見えました(遅いラップトップで許可されています)。したがって、numpy には平凡なコーディングよりも高速にこれを行う方法が必要であると考え、ドキュメントを見て、次のことを試しました。
indices = [k for k in numpy.ndindex(q.shape)]
which took about 4.5 SECONDS (wtf?)
indices = [x for x,i in numpy.ndenumerate(q)]
better, but 1.5 seconds!
これを行うより速い方法はありますか?
ありがとう