简体   繁体   中英

Numpy: Looking for efficient way to multiply a vector with a vandermonde matrix

Given two arrays A and B with the same size: N , I'm trying to calculate the following product:

np.dot(A, np.vander(B, increasing=True))

However, If N becomes very large, I will eventually encounter an insufficient memory error.

This makes sense since the memory complexity is N^2 .

Is there an efficient way to do this with memory complexity of N (ie avoiding initializing the vandermonde matrix), without using any loops?

Any help will be appreciated!

Based on the documentation of the vandermonde matrix you can construct it in the following way:

np.vander(B, increasing=True) == np.column_stack([B**(i) for i in range(len(B))])

So your optimization would be to do dot product in-place:

np.column_stack([np.dot(A, B**(i)) for i in range(len(B))])

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM