1

I have an huge 8D array view that i want to reduce to 2D by multiplying the elements together over 4 axes and summing them over 2 axes. I didn´t find any example in the numpy.einsum documentation where the elements of the same array are multiplied with each other. The following works, but requires a lot of additional memory during computation:

import numpy as np
a = np.zeros((2048,2048,64,64,dtype=float32)
a[...] = data
b = np.lib.stride_tricks.sliding_window_view(a,(3,3)+a.shape[2:],axis=(0,1,2,3))
c = np.sum(np.prod(b,axis=(2,3,4,5)),axis=(2,3))

Can this operation be performed by numpy.einsum to save memory?

1
  • 1
    You cannot multiply elements of the same array with each other using einsum. and the purpose of numpy.einsum is not to save memory. Your code is already looks good. break it into small chucks and run if you cannot fit it into memory. The memory required to create aarray is around 64 gb. So it is not the issue of the function. Commented Aug 1, 2022 at 20:05

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.