アットウィキロゴ

numpy で for iterationをindex付きでまわす

numpy.ndenumerateが使えます。
http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndenumerate.html
indexは(d1, d2, d3, ...)のようなtupleになります。

import numpy as np
a = np.array([[1, 2], [3, 4]])
for index, x in np.ndenumerate(a):
print index, x

=== output ===
(0, 0) 1
(0, 1) 2
(1, 0) 3
(1, 1) 4
























タグ:

python numpy
最終更新:2013年02月19日 18:52