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 を使用している場合は、ジェネレーター式の代わりに配列全体の式を使用できますが、その場合は numpy 配列cで なければなりません。r
c
r
def compute(c, r): return (c*f(r)).sum()