如何使用Python的隱式循環編寫以下循環?數組廣播與numpy
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
「隱式循環」?你可以定義嗎? – nosklo 2010-08-09 18:59:54
我想我的意思是「陣列廣播」:) – 2010-08-09 19:11:03