我有以下代码可以正常工作:
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
从左到右执行累积乘积。我该如何从右向左反转呢?
答案 0 :(得分:0)
您应该反转数组,例如V = V [::-1]