I have an array:
a = np.array([1, 2, 3, 1, 3, 4, 2, 4])
and I want to do the following calculation:
out = 0
for e in a:
out *= 3
out += e
With out as the output (4582 for the given example), is there a nice way to vectorize this? I think einsum can be used, but I couldn't figure how to write it.