【发布时间】:2010-08-09 18:56:49
【问题描述】:
如何使用 Python 的隐式循环编写以下循环?
def kl(myA, myB, a, b):
lots of stuff that assumes all inputs are scalars
x, y = meshgrid(inclusive_arange(0.0, xsize, 0.10),\
inclusive_arange(0.0, ysize, 0.10))
for j in range(x.shape[0]):
for i in range(x.shape[1]):
z[j, i] = kl(x[j, i], y[j, i])
我想做类似的事情
z = kl(x, y)
但这给出了:
TypeError: only length-1 arrays can be converted to Python scalars
【问题讨论】:
-
“隐式循环”?你能定义一下吗?
-
我想我的意思是“阵列广播”:)