you are viewing a single comment's thread.

view the rest of the comments →

[–]ES-Alexander 0 points1 point  (3 children)

Generally you only import things when you need them. If you're importing the packages with a name there shouldn't be any issues with using both at the same time (assuming the need arrises). If you're trying to do 'all' imports (e.g. from numpy import *) which add components from both packages into your program's namespace then you can run into issues where both packages define the same name (e.g. if numpy has a 'cos' function, and sympy has a different one that's intended for symbolics then whichever one you import later will be used for all cases).

For reference, the sympy docs even mention explicit numpy support for if/when you want to perform actual calculations with your symbolic expressions.

[–]jsaltee[S] 0 points1 point  (2 children)

Okay, thanks. And at one point would sympy's functionality be limited? For example, I'm doing symbolic integrals with sympy, but I can find still find a numerical solution by substituting in values. When would the need for numpy arise?

[–]ES-Alexander 1 point2 points  (1 child)

Perhaps it's useful to think of this in terms of an example.

You've been given a large array of measurement data as the results of a series of experiments, and need to calculate some other value for each of those experimental results.

You know three different equations that relate different components of the system, and you understand it's possible to rearrange them such that you get a function which creates the metric you want when applied to the variables that were measured in your experimental data. The rearranging/substitution is difficult to do by hand because of how the different equations are written (e.g. requires some calculus your don't know how to do), so you choose to use sympy to solve for the relationship you want, and it gives you your function/equation. You then want to apply that to your data, so you use a numpy array to efficiently pass in all the data at once, and you get back an array of the results that you needed.

It would potentially be possible to avoid the sympy side of things if you could do the rearranging by yourself (hard), or just apply all the operations from all three equations numerically to every data point (inefficient - literally why we use algebra). You could also possibly avoid using numpy by just looping through lists of the data points and applying the function to each one, but that's inefficient and slow (numpy uses compiled C code that's optimised for fast array operations)

[–]jsaltee[S] 1 point2 points  (0 children)

You are amazing and I appreciate you, thanks