I am trying to do something like the following:
import numexpr as ne
a = np.random.rand(10, 1)
b = np.random.rand(1, 10)
ne.NumExpr('sum(sum(a*b, 1), 0)').run(a, b) # <- error: reduction operations must occur last
ne.NumExpr('sum(a*b, [1, 0])').run(a, b) # <- error: ValueError: cannot encode axis
This returns with the error documented here:
https://github.com/pydata/numexpr/wiki/Numexpr-Users-Guide#supported-reduction-operations
I was wondering if there is a workaround that I haven't thought of.
EDIT
To answer some comments:
This is a simpler example than the actual one I'm interested in. A more complete example exists here:
How to sum of squares of sum with memory limitations?
and here:
How to do a sum of sums of the square of sum of sums?
I don't expect you to read through those questions.
The primary reason I was interested in a numexpr
implementation is that it offers easy support for multithreading compared to anything else I've seen, and the reduction operators reduce the need for memory storage which at times is crucial in my case.
I hope this clears a few things up.
How about using two expressions?
I am not sure if this is a solution for you but this would avoid the limited usage of functions/sums in numexpr.