python - Multiply array with diagonal matrix stored as vector -


i have 1d array = [a, b, c...] (length n_a) , 3d array t of shape (n_a, n_b, n_a). meant represent diagonal n_a n_a matrix.

i'd perform contractions of t without having promote dense storage. in particular, i'd

np.einsum('ij, ikl', a, t) 

and

np.einsum('ikl, lm', t, a) 

is possible such things while keeping sparse?

note question similar

dot product diagonal matrix, without creating full matrix

but not identical, since it's not clear me how 1 generalizes more complicated index patterns.

np.einsum('ij, ikl', np.diag(a), t) equivalent (a * t.t).t.

np.einsum('ikl, lm', t, np.diag(a)) equivalent a * t.

(found trial-and-error)


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -