Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
def compute(c, r): s = 0; l = len(c); for i in range(l): s = s + c[i]*f(r[i]); return s
我不知道你所说的向量形式是什么意思(除非你使用 numpy?),但我会这样写你的函数:
def compute(c, r): return sum(x*f(y) for x,y in zip(c,r))
如果您使用的是 numpy,则可以使用整个数组表达式而不是生成器表达式,但在这种情况下c, r必须是 numpy 数组:
c
r
def compute(c, r): return (c*f(r)).sum()
用jquery标记?