2019-01-24
阅读量:
808
python如何实现广播迭代
广播迭代:
如果两个数组是可广播的,则组合的nditer对象能够同时迭代它们。假设数组a的维度为3X4,并且存在另一个维度为1X4的数组b,则使用以下类型的迭代器(数组b广播为a的大小)。
# Python program for# iterating array
import numpy as geek
# creating an array using arrange # method a = geek.arange(12)
# shape array with 3 rows and # 4 columns a = a.reshape(3,4)
print('First array is:') print(a)print()
# Creating second array using # array methodprint('Second array is:') b = geek.array([5, 6, 7, 8], dtype = int) print(b) print()
print('Modified array is:')for x,y in geek.nditer([a,b]):
print("%d:%d" % (x,y))
46.1538
1
2
关注作者
收藏
评论(0)
发表评论
暂无数据
推荐帖子
0条评论
0条评论
0条评论

