-
Moving the ideas mentioned by @ThePauliPrinciple in #22265 (comment) to this separate discussion. See also the indexing ideas mentioned by @ThePauliPrinciple in #22219. It seems that it is not yet possible to perform computations on the axes of (symbolic) arrays. This would be required for creating expressions that can be lambdified to To simplify things, let's stick with this sum as an example. We would like to do something like this: >>> from sympy.tensor.array.expressions.array_expressions import ArraySymbol
>>> A = ArraySymbol("A")
>>> expr = A.sum(axis=1) # or some other syntax; probably requires a new Sum class
>>>
>>> from sympy.printing.numpy import NumPyPrinter
>>> NumPyPrinter().doprint(expr)
'numpy.sum(A, axis=1)'
>>>
>>> from sympy.printing.tensorflow import TensorflowPrinter
>>> TensorflowPrinter().doprint(expr)
'tf.math.reduce_sum(A, axis=1)' Is this perhaps already possible? Or are there ideas for some implementation? |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 26 replies
-
Instead of a new Sum class |
Beta Was this translation helpful? Give feedback.
-
I'm not too familiar with >>> import numpy as np
>>> A = np.arange(9).reshape(3, 3); A
array([[0, 1, 2],
[3, 4, 5],
[6, 7, 8]])
>>>
>>> np.einsum("ij->i", A) # np.sum(A, axis=1)
array([ 3, 12, 21])
>>> np.einsum("ji->i", A) # np.sum(A, axis=0)
array([ 9, 12, 15])
>>>
>>> np.einsum("ij->i", A.transpose())
array([ 9, 12, 15])
>>> np.einsum(A, [0, 1], [0]) # np.sum(A, axis=1)
array([ 3, 12, 21]) The last one was added, because perhaps something can be done with a combination of Lines 270 to 274 in 3abd23d |
Beta Was this translation helpful? Give feedback.
-
ArrayContraction(..., (1,)) This is equivalent to |
Beta Was this translation helpful? Give feedback.
-
For reference, I decided to base the class |
Beta Was this translation helpful? Give feedback.
ArrayContraction
can be given single axes:This is equivalent to
numpy.sum(..., axis=1)