[英]How to simplify a for loop in python
I have this piece of Python code that fills up a 2d matrix in a for loop 我有这段Python代码填充for循环中的2d矩阵
img=zeros((len(bins_x),len(bins_y)))
for i in arange(0,len(ix)):
img[ix[i]][iy[i]]=dummy[i]
Is it possible to use a vectorial operation for the last two lines of code? 是否可以对最后两行代码使用矢量运算? Is there also something that might speed up the calculation? 还有什么东西可以加快计算速度吗?
如果是ix,我是索引序列:
img[ix, iy] = dummy
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.