I tried to calculate the cumulative products for my list elements as below. In my list, each element is two-dimensional list:
import numpy as np
Orig_list = [[[1,2,3], [4,5,6], [7,8,9]], [[11,3,4], [22, 4, 5], [22, 5, 1]], [[7,6,7], [2,5,6], [4,6,7]], [[234, 56, 22], [44, 66, 33], [44, 66, 33]]]
Result_list = [np.nan] * 4
Result_list[0] = Orig_list[0]
for i in range(1, len(Result_list)):
Result_list[i] = (np.array(Result_list[i - 1]) @ np.array(Orig_list[i])).tolist()
The above works, but I am looking for cleaner and faster implementation as my original list is fairly big and each element is also a large two-dimensional list.
Is there anything like a more direct cumulative product function/method for above calculation?
@operator).pandas.DataFrame.cumprod(andnumpy.cumprod) seems useless for this.Result_listafter theirforloop (which produces, as mentioned, the desired result, but which, being a loopy solution, they want to avoid)