python - Matrix of polynomial elements -


i using numpy operations on matrices, calculate matrixa * matrixb, trace of matrix, etc... , elements of matrices integers. want know if there possibility work matrices of polynomials. instance can work matrices such [x,y;a,b], not [1,1;1,1], , when calculate trace provides me polynomial x + b, , not 2. there polynomial class in numpy matrices can work with?

one option use sympy matrices module. sympy symbolic mathematics library python quite interoperable numpy, simple matrix manipulation tasks such this.

>>> sympy import symbols, matrix >>> numpy import trace >>> x, y, a, b = symbols('x y b') >>> m = matrix(([x, y], [a, b])) >>> m matrix([ [x, y], [a, b]]) >>> trace(m) b + x >>> m.dot(m) [a*y + x**2, a*b + a*x, b*y + x*y, a*y + b**2] 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -