Replacing a scalar/symbol by an array #26532
-
Dear community, I would like to replace all the symbols in a given expression by arrays all of the same length. Doing this would basically turn a scalar equation into a vector valued equation. As far as I know, simply replacing all those symbols by corresponding array symbols isn't allowed. Now the reason I would even want to do this is because I need to evaluate some expression a large number of times. In order to make this computation more efficient I figured I could substitute in all my constants (measurements) at once and lambdify this expression, or ideally transform it into a form acceptable by PyTorch. Here is an example of the code:
This yields expressions of W and P that are dependent on the individual components of F. The thing is that I have multiple evaluations of F. I would therefore either like to replace the scalar element with an array of values or extend the dimension of F after performing these manipulations to the expression. I could then use subs() or xreplace() to substitute in my measurement values. If anyone knows how to perform such an "illegal" manipulation that would be greatly appreciated. Other comments and criticisms are also more than welcome. Edit: replaced item.expr with W and added sympy import to be explicit |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Your code fails for me:
|
Beta Was this translation helpful? Give feedback.
-
Thank you for your help! I will close this discussion as I have no further questions on this topic. |
Beta Was this translation helpful? Give feedback.
lambdify is using numpy under the hood. If you know that the numerical inputs to your functions are too large for numpy (i.e. working in memory), then you'll need to use other ways to evaluate the functions. But if your data fits in memory and works fine with NumPy, I don't see any issue with what you have written in your
#multiple measurements
statement.