Is there a python module to solve linear equations?

后端 未结 6 907
生来不讨喜
生来不讨喜 2020-11-27 16:32

I want to solve a linear equation with three or more variables. Is there a good library in python to do it?

6条回答
  •  一生所求
    2020-11-27 16:56

    Yes, the very-popular NumPy package has a function to do this. Their example:

    Solve the system of equations 3 * x0 + x1 = 9 and x0 + 2 * x1 = 8:

    >>> import numpy as np
    >>> a = np.array([[3,1], [1,2]])
    >>> b = np.array([9,8])
    >>> x = np.linalg.solve(a, b)
    >>> x
    array([ 2.,  3.]) 
    

    https://docs.scipy.org/doc/numpy-1.13.0/reference/generated/numpy.linalg.solve.html

提交回复
热议问题