1. Using for-loop
Iterate along row axis:
1 import numpy as np 2 x=np.array([[1,2,3],[4,5,6]]) 3 for i in x: 4 print(x)
Output:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 }
span.s1 { }
[1 2 3]
[4 5 6]
2. Using ndenumerate object
for index, i in np.ndenumerate(x): print(index,i)
Output:
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #000000 }
span.s1 { }
(0, 0) 1
(0, 1) 2
(0, 2) 3
(1, 0) 4
(1, 1) 5
(1, 2) 6
3. Using nditer object
See: https://docs.scipy.org/doc/numpy-1.15.0/reference/arrays.nditer.html
原文地址:https://www.cnblogs.com/sherrydatascience/p/10206788.html
时间: 2024-10-15 10:27:28