У меня следующий код отлично работает:
import numpy as np
def transformation(C):
# Transform 0 and 1 to -1 and +1.
V = 2. * C - 1
# Compute the cumulative product from left to right
V = np.cumprod(V, dtype=np.int8)
return V
C = np.random.choice(np.array([0, 1], dtype=np.int8), size=(3,))
C = transformation(C)
Как видите, np.cumprod
выполняет накопленное произведение слева направо. Как я могу изменить это, чтобы быть справа налево вместо этого?