2

I am currently working with large numpy array multiplications, using numpy.einsum, and have been facing MemoryError issue. That is why I'm trying to evaluate expressions, wherever possible, with numexpr. As far as I understand:

np.einsum('ij,j -> ij', a, b)

is technically the same as

numexpr.evaluate("a*b")

However, things seems to be not so straightforward in other cases. Suppose I have three expressions:

np.einsum('i, j -> ij', a, b)
np.einsum('ij, i -> ij', a, b)
np.einsum(ijk, kl -> ijkl', a, b)

What would be the equivalent way of achieving these three using numexpr?

konstant
  • 685
  • 1
  • 7
  • 19
  • There exists no convenient 1:1 mapping between one and the other. However, if you know what one does, you can just spell it out with the other. – cs95 May 11 '18 at 21:08
  • 1
    All those examples can be expressed as `*` multiplication with broadcasting. They don't involve any `dot` like summation of products, just some form of `outer` product. e.g. `a[:,None]*b`, `a*b[:,None]`, `a[...,None]*b`. – hpaulj May 11 '18 at 21:23
  • @hpalj what is the advantage of expressing as `*` in comparision to just the ususal `einsum`? – konstant May 11 '18 at 22:30
  • Usually einsum is used for selected sums of products, not just products. – hpaulj May 12 '18 at 04:52

0 Answers0