python - How to nicely handle [:-0] slicing? -
in implementing autocorrelation function have term like
for k in range(start,n): c[k] = np.sum(f[:-k] * f[k:])/(n-k)
now works fine if start = 1
i'd handle nicely start @ 0
case without conditional.
obviously doesn't work because f[:-0] == f[:0]
, returns empty array, while i'd want full array in case.
don't use negative indices in case
f[:len(f)-k]
for k == 0
returns whole array. other positive k
it's equivalent f[:-k]
Comments
Post a Comment