I doubt there's much speed difference vs. a list, since using any non-NumPy data type (i.e., any SymPy data type) in a NumPy array results in dtype=object
, meaning the array is just an array of pointers (which a list
is too).
It's really unclear why you want to use a NumPy array?
The first question is, why don't you want to use float64
? Assumedly you are using
- Symbolic expressions (such as
x**2
or pi
),
- Rational numbers, or
sympy.Float
objects with higher precision
Those are the only reasons I can think of that you would want to prefer a SymPy type over a NumPy one.
The main advantage of using a NumPy array would be if you want to take advantage of NumPy's superior indexing syntax. As Stelios pointed out, you can get much of this by using SymPy's tensor module. This is really the only reason to use them, and you have to be careful and be aware of which NumPy methods/functions will work and which won't.
The reason is that any NumPy mathematical function will not work (or at best, will convert the array to float64
first). The reason is that NumPy functions are designed to work on NumPy data types. They don't know about the above data types. To get exact values (symbolic expressions or rational numbers), or higher precision floating point values (for the case of sympy.Float
), you need to use SymPy functions, which do not work on NumPy arrays.
If on the other hand (again, it's not clear what exactly you are trying to do), you want to do calculations in SymPy and then use NumPy functions to numerically evaluate the expressions, you should use SymPy to create your expressions, and then lambdify
(or ufuncify
if performance becomes an issue) to convert the expressions to equivalent NumPy functions, which can operate on NumPy arrays of NumPy dtypes.