以下是我期望返回向量但返回标量的python代码。为什么lambda和np.fromfunction在这种情况下没有按预期工作?
>>> import numpy as np
>>> b = [1,2,3]
>>> squarer = lambda t: np.sum(b)
>>> a = np.fromfunction(squarer, (3,), dtype=int)
>>> a
6
具体在我的情况下,下面是返回标量的实际代码。 trx和托盘是数组。
>>>exp = lambda j: np.sum(np.fromfunction(lambda i: alpha[i] *\
(1 + trx[i]*tray[j])**pow, (size,), dtype=int))
>>>a = np.fromfunction(exp, (tray.shape[0], ), dtype=int)
>>>a
1545