首页 > 编程语言 > 详细

[Python Cookbook] Numpy: Iterating Over Arrays

时间:2019-01-02 10:32:59      阅读:173      评论:0      收藏:0      [点我收藏+]

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:

[1 2 3]

[4 5 6]

 

2. Using ndenumerate object

for index, i in np.ndenumerate(x): 
print(index,i)

Output:

(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

  

[Python Cookbook] Numpy: Iterating Over Arrays

原文:https://www.cnblogs.com/sherrydatascience/p/10206788.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!