'Efficiently isolating the coefficients and exponents of an array of polynomials (Python)

In Python, I do some SymPy calculations that yield an array full of polynomials in the variables a, b, c, d, e and f such as:

array([b*d*e*f, 0, 0, d**3*e, b*d*e**2 + d**3*e + 2*d**2*e**2 + d*e**3,
       b**2*d*e + b**2*e**2 + b*c*e*f + b*d**2*e + 2*b*d*e**2 + b*e**3 + 2*d**2*e**2 + d*e**3,
       b**2*d*e + 2*b**2*e**2 + b**2*e*f + 2*b*c*e*f + b*d**2*e + b*d*e**2 + 2*b*e**3,
       a*b*e*f + b**2*e**2 + b**2*e*f + b*c*e*f + b*e**3])

This is just a basic illustrative example. In my actual code, the number of terms in each polynomial and the size of the exponents is much larger.

Once I have this expression, I need to extract the coefficients and exponents from each term in every entry of the array. So far, I have tried some SymPy methods such as

Poly(p,a,b).coeff_monomial(b**i*a**(j))

Another method I tried, was converting the polynomial to a string and performing some string manipulations in order to extract the necessary coefficients. Both methods yield the required results of course, but due to the size of the polynomials, I found that they are far too slow.

So my question: can anyone point me in the direction of some packages or methods that I might still be unaware of and that are (performance-wise) ideally suited to solve this issue I am having?

Any help would be majorly appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source