I am interested in calculating a large NumPy array. I have a large array A
which contains a bunch of numbers. I want to calculate the sum of different combinations of these numbers. The structure of the data is as follows:
A = np.random.uniform(0,1, (3743, 1388, 3))
Combinations = np.random.randint(0,3, (306,3))
Final_Product = np.array([ np.sum( A*cb, axis=2) for cb in Combinations])
My question is if there is a more elegant and memory efficient way to calculate this? I find it frustrating to work with np.dot()
when a 3-D array is involved.
If it helps, the shape of Final_Product
ideally should be (3743, 306, 1388). Currently Final_Product
is of the shape (306, 3743, 1388), so I can just reshape to get there.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…