Is there any way to vectorize this expression?
import numpy as np
def phase(f, dt=1):
c = [f[0]] + [fi*dt for fi in f[1:]]
s=0
x = []
for ci in c:
s = (s+ci)%(2*np.pi)
x.append(s)
return x
f is an array of arbitrary length, dt is a constant.
The code does:
- multiply the whole vector
fbut the first instance bydt. - return the partial sum i.e.
output[i] = sum(c[0:i])modulo2pi.
Any idea on how to speed it up? Thank you!