K i"ddlmZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z mZddlmZmZdd lmZdd lmZdd lmZdd lmZmZdd lmZmZddlmZddl m!Z!ddl"m#Z#m$Z$m%Z%ddl&m'Z'ddl(m)Z)m*Z*m+Z+ddl,m-Z-m.Z.ddl/m0Z0ddl1m2Z2ddl3m4Z4ddl5m6Z6m7Z7ddl8m9Z9m:Z:ddl;Zm?Z?ddl@mAZAddlBmCZCddlmDZDdd lEmFZFmGZHdd!lImJZJdd"l>mKZKmLZLdd#lMmNZNmOZOdd$lPmQZQdd%lRmSZSmTZTdd&lUmVZVdd'l>mWZWdd(lEmXZXdd)lYmZZZdd*l[m\Z\m]Z]m^Z^m_Z_dd+lEm`Z`maZadd,lbmcZcmdZdmeZemfZfmgZgmhZhmiZimjZjmkZkmlZlmmZmmnZnmoZompZpmqZqdd-lrmsZsmtZtmuZumvZvdd.lwmxZxmyZymzZzm{Z{m|Z|m}Z}m~Z~mZmZmZmZmZdd/lmZmZmZmZmZmZmZmZmZdd0lmZmZmZmZdd1lmZmZmZmZmZmZmZmZmZmZmZmZmZmZdd2lmZmZmZmZmZmZmZmZmZdd3lmZmZmZmZd4d5giZGd6d7e2Zd8Zd9Zd:Zd;Zd<Zd=ZdAd>ZGd?d@eeWZy)B) annotations) defaultdict)Iterable) isfunction)reducerefine) SympifyErrorAdd)AtomBasic) UndefinedKind)IntegerMod)SymbolDummy)sympify_sympifydiff)cancel)Absreimsstr)MaxMinsqrt)KroneckerDelta LeviCivita)S) Printable) StrPrinter)explog)binomial factorialN)Callable)reshape)Expr)Pow)uniquely_named_symbol) _dotprodsimp _simplify)Poly)flatten is_sequence)as_int filldedent)call_highest_priority) fuzzy_and FuzzyBool) NDimArray) NotIterable)_get_intermediate_simp_bool) MatrixKind) MatrixError ShapeErrorNonSquareMatrixErrorNonInvertibleMatrixError)_iszero_is_zero_after_expand_mul)_find_reasonable_pivot_find_reasonable_pivot_naive _adjugate _charpoly _cofactor_cofactor_matrix_per_det _det_bareiss_det_berkowitz _det_bird _det_laplace_det_LU_minor_minor_submatrix) _is_echelon _echelon_form_rank_rref) _diagonal_solve_lower_triangular_solve_upper_triangular_solve_cholesky_solve _LDLsolve_LUsolve_QRsolve_gauss_jordan_solve _pinv_solve _cramer_solve_solve_solve_least_squares) _pinv_inv_ADJ_inv_GE_inv_LU_inv_CH_inv_LDL_inv_QR_inv _inv_block) _columnspace _nullspace _rowspace_orthogonalize) _eigenvals _eigenvects_bidiagonalize_bidiagonal_decomposition_is_diagonalizable _diagonalize_is_positive_definite_is_positive_semidefinite_is_negative_definite_is_negative_semidefinite_is_indefinite _jordan_form_left_eigenvects_singular_values) _rank_decomposition _cholesky_LDLdecomposition_LUdecomposition_LUdecomposition_Simple_LUdecompositionFF_singular_value_decomposition_QRdecomposition_upper_hessenberg_decomposition)_connected_components#_connected_components_decomposition_strongly_connected_components,_strongly_connected_components_decomposition)zMatrixBase.is_indefinitezMatrixBase.is_positive_definitez#MatrixBase.is_positive_semidefinitezMatrixBase.is_negative_definitez#MatrixBase.is_negative_semidefinite matplotlibceZdZUdZdZdZdZdZee Z e jZ e jZdZded<ded <ded <d Zed Zd ZdZedZdZdZdZdZdZdZdZdZ dZ!dZ"edZ#dZ$dZ%dZ&dZ'dZ(d Z)d!Z*d"Z+ed#Z,d$Z-d%Z.d&Z/d'Z0d7d(Z1d)Z2d*Z3ed+Z4d,Z5d-Z6d.Z7d8d/Z8ed0Z9ed1Z:ed2Z;ed9d:d4Zed7Z?ed8dd d d9d:Z@ed;d;ZAedZCed;d?ZDed@ZEedAZFdBZGdCZHdDZIdEZJdFZKdGZLdHZMdIZNdJZOd=dKZPdLZQdMZRdNZSdOZTdPZUdQZVdRZWdSZXdTZYdUZZedVZ[dWZ\d>dXZ]dYZ^edZZ_ed[Z`ed\Zaed=d]Zbed^Zced_Zded`ZedaZfd>dbZgedcZheddZiedeZjdfZkdgZldhZmdiZndjZodkZpdlZqdmZrdnZsdoZtdpZudqZvdrZwd>dsZxdtZyduZzd?dvZ{ d@dwZ|edxZ}dAdyZ~dBdzZdBd{Zd>d|ZdCd}ZdDd~ZdZdZdZdZedZedZdZdZdZdZd7dZd7dZdZdZdZdZdZdZdZd;dZdZdZdZdZeddZeddZeddZdZeddZd;dZdZdZeddZd;dZeddZeddZeddZd;dZeddZeddZefdZdZed fdZdZdZdZdEdZdefdZdEdZdEdZdFdZdZdEdZdZeje_eje_eje_eje_eje_eje_eje_eje_eje_eje_eje_eje_eje_eje_eje_eje_ed8d8fdZedZed8fd„ZdÄZed8ddfdĄZeje_eje_eje_eje_dGdńZdƄZdDŽZdȄZdɄZdʄZd˄ZܐdHd̄ZݐdHd̈́ZސdId΄Zd8efdτZdIdЄZdфZeje_eje_eje_eje_eeZd>d҄ZdefdӄZdIdԄZdJdՄZd>dքZd>dׄZed؄ZedلZedڄZedۄZed܄Zd>d݄ZdބZd߄Zeje_eje_eje_eje_eje_eje_eje_eje_eje_eje_eje_eje_eje_eje_dddZdZdZdZdZedefdZ dZ dZ dZ dZ dEdZdZdZdZd>dZdEdZdZdZdZedKdZdZed fdZdZdZdZd;dZedZedZ edZ!dZ"dZ#dZ$dZ%dZ&dZ'dZ(edZ)d<dZ*dZ+dZ,d Z-d Z.d Z/e0fd Z1d Z2dZ3dZ4efdZ5d;dZ6dLdZ7dZ8 dMdZ9ed8fdZ:d>dZ;d>dZdZ?dZ@dZAdZBdZCdZDd ZEd!ZFd"ZGefd#ZHd$ZIdId%ZJd;d&ZKdNd'ZLdOd(ZMdPd)ZNdQd*ZOefd+ZPefd,ZQefd-ZRefd.ZSefd/ZTefd0ZUefd1ZVd ed8fd2ZWd3ZXd4ZYd5ZZd>d6Z[e\jZ]e^je:_e_je;_e`je<_eaje=_ebje>_ecje?_edje@_eejeA_efjeB_egjeC_ehjeD_eijeE_ejjeF_ekjeG_eljeH_emjeI_enjeJ_eojeK_epjeL_eqjeM_erjeN_esjeO_etjeP_eujeR_evjeS_ewjeT_exjeU_eyjeV_ezjeQ_e{jeW_e|jeX_e}jeY_e~jeZ_eje[_y (R MatrixBasezsAll common matrix operations including basic arithmetic, shaping, and special matrices like `zeros`, and `eye`.gQ$@ Tbool _diff_wrtintrowscolsNctd)z`_new` must, at minimum, be callable as `_new(rows, cols, mat) where mat is a flat list of the elements of the matrix.Subclasses must implement this.NotImplementedError)clsargskwargss _/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/matrices/matrixbase.py_newzMatrixBase._neww ""CDDctd)Nrrselfothers r__eq__zMatrixBase.__eq__~s!"CDDrctd)aImplementations of __getitem__ should accept ints, in which case the matrix is indexed as a flat list, tuples (i,j) in which case the (i,j) entry is returned, slices, or mixed tuples (a,b) where a and b are any combination of slices and integers.rr)rkeys r __getitem__zMatrixBase.__getitem__rrc2|j|jfS)a The shape (dimensions) of the matrix as the 2-tuple (rows, cols). Examples ======== >>> from sympy import zeros >>> M = zeros(2, 3) >>> M.shape (2, 3) >>> M.rows 2 >>> M.cols 3 rrrs rshapezMatrixBase.shapes  499%%rcffd}jjjdz |S)Nc0|kr||fS||dzfSNr/)ijcolrs rentryz'MatrixBase._eval_col_del..entrys(!"S41: .entrysY3wAqDz!,C%**,,QCZ((1uzz>)* *rr)rrrrs``` r_eval_col_insertzMatrixBase._eval_col_inserts. +yyDII $:EBBrcjfd}tjjjzj|S)Nc0|kr||fS|z |fSrr)rrrrrs rrz(MatrixBase._eval_col_join..entrys+4xAqDz!T1% %r)rclassofrr)rrrrs`` @r_eval_col_joinzMatrixBase._eval_col_joinsEyy & tU#((UZZ)?).0 0rc t|}|jfd|D}|jt|t|Dcgc]}|| c}Scc}w)Nc3<K|]}D] }|z|zywrr).0rrrcolsLists r z+MatrixBase._eval_extract..s%DA8Da1t8a<D<D)listrrlen)rrowsListrmatindicesrrs ` @r _eval_extractzMatrixBase._eval_extractsQ4jyyDDyyXH *12Q#a&24 42s A c*gfd|S)Ncntd|jddzD]}|dk(r|d|df}||ddf}n|d||df}||dd|f}t|s t|rHj|d|d|f|j|d|d|fjk7r||d|dfyy)Nr/r)rangeranyappend)Mr to_the_right to_the_bottomrecurse_sub_blocks sub_blockss rrz.recurse_sub_blockss1aggaj1n- 6#$QU8L$%ab!eHM#$RaRV9L$%ab"1"fIM|$M(:!!!BQBF),77aBQBioo-&qQRy1 rr)rrrs @@r_eval_get_diag_blocksz MatrixBase._eval_get_diag_blockss   4 rcffd}jjdz j|S)Nc0|kr||fS|dz|fSrr)rrrowrs rrz'MatrixBase._eval_row_del..entrys(!"S41: .entrys+4xAqDz!AH% %r)rrrr)rrrrs`` @r_eval_row_joinzMatrixBase._eval_row_joinsEyy & tU#((DII 4J).0 0rc rt|jDcgc]}t||ddfc}Scc}wr)rrrrrs r _eval_tolistzMatrixBase._eval_tolists+).tyy)9:AT!A#Y:::s4ci}|j\}}t|D]0}t|D] }|||f}||jk7s||||f<"2|Sr)rrzero)rdokrrrrvals r _eval_todokzMatrixBase._eval_todoksgZZ dt $A4[ $1a4j$))# #C1I $ $  rc|jg||zz}|jD]\\}}}||||z|z<|j|||Sr)ritemsr)rrrrout_flatrrrs r_eval_from_dokzMatrixBase._eval_from_doksXHH:-99; )KFQC%(HQX\ " )xxdH--rcbjfd}jtd|S)Nc,|z}||zz }||fSrr)n_rrrrs rrz#MatrixBase._eval_vec..entrys'T AAH A1: rr/)rrr)rrrs` @r _eval_veczMatrixBase._eval_vecs*yy  yyTAu--rc>|j}g}|r8t|D])}t||D]}|j|||f+n:t|D],}t|dz|D]}|j|||f.|jt |d|Sr)rrrrr)rdiagonalcvrrs r _eval_vechzMatrixBase._eval_vechs II  1X )q!)AHHT!Q$Z() )1X )q1ua)AHHT!Q$Z() )yyQA&&rc|dkr||jz }d|cxkr|jksntdj||j|S)zDelete the specified column.rzColumn {} is out of range.)r IndexErrorformatr)rrs rcol_delzMatrixBase.col_delsP 7 499 CC#$))#9@@EF F!!#&&rc`|st||St|}|dkr|j|z}|dkrd}n||jkDr |j}|j|jk7r/t dj |j|j|j ||S)ayInsert one or more columns at the given column position. Examples ======== >>> from sympy import zeros, ones >>> M = zeros(3) >>> V = ones(3, 1) >>> M.col_insert(1, V) Matrix([ [0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0]]) See Also ======== col row_insert r9The matrices have incompatible number of rows ({} and {}))typer5rrr?rrrrrs r col_insertzMatrixBase.col_inserts,4:e$ $Sk 7))c/C 7C 499_))C 99 "K 5::.0 0$$S%00rc\|jdk(rE|j|jk7r,|jd|jgj|S|j|jk7r/t dj |j|j|j |S)aConcatenates two matrices along self's last and other's first row. Examples ======== >>> from sympy import zeros, ones >>> M = zeros(3) >>> V = ones(1, 3) >>> M.col_join(V) Matrix([ [0, 0, 0], [0, 0, 0], [0, 0, 0], [1, 1, 1]]) See Also ======== col row_join rdii5::599Q B/88? ? 99 "N 5::.0 0""5))rc|dd|fS)aElementary column selector. Examples ======== >>> from sympy import eye >>> eye(2).col(0) Matrix([ [1], [0]]) See Also ======== row col_del col_join col_insert Nr)rrs rrzMatrixBase.colds(AqDzrct|r t|s td|r2td|Dr t|Dcgc] \}}|s | }}}|r2td|Dr t|Dcgc] \}}|s | }}}|Dcgc]}t ||j }}|Dcgc]}t ||j }}|j||Scc}}wcc}}wcc}wcc}w)aReturn a submatrix by specifying a list of rows and columns. Negative indices can be given. All indices must be in the range $-n \le i < n$ where $n$ is the number of rows or columns. Examples ======== >>> from sympy import Matrix >>> m = Matrix(4, 3, range(12)) >>> m Matrix([ [0, 1, 2], [3, 4, 5], [6, 7, 8], [9, 10, 11]]) >>> m.extract([0, 1, 3], [0, 1]) Matrix([ [0, 1], [3, 4], [9, 10]]) Rows or columns can be repeated: >>> m.extract([0, 0, 1], [-1]) Matrix([ [2], [2], [5]]) Every other row can be taken by using range to provide the indices: >>> m.extract(range(0, m.rows, 2), [-1]) Matrix([ [2], [8]]) RowsList or colsList can also be a list of booleans, in which case the rows or columns corresponding to the True values will be selected: >>> m.extract([0, 1, 2, 3], [True, False, True]) Matrix([ [0, 2], [3, 5], [6, 8], [9, 11]]) z&rowsList and colsList must be iterablec3<K|]}t|tywr isinstancerrrs rrz%MatrixBase.extract..BAJq$/Bc3<K|]}t|tywrrr s rrz%MatrixBase.extract..r r )r4 TypeErrorall enumeratea2idxrrr)rrrindexitemks rextractzMatrixBase.extractzs`8$K,ADE E BBB1:81DM+%MHM BBB1:81DM+%MHM2::AE!TYY'::19:AE!TYY'::!!(H55NM;:s$ C"C"8 C(C(C.1C3c"|jS)azObtains the square sub-matrices on the main diagonal of a square matrix. Useful for inverting symbolic matrices or solving systems of linear equations which may be decoupled by having a block diagonal structure. Examples ======== >>> from sympy import Matrix >>> from sympy.abc import x, y, z >>> A = Matrix([[1, 3, 0, 0], [y, z*z, 0, 0], [0, 0, x, 0], [0, 0, 0, 0]]) >>> a1, a2, a3 = A.get_diag_blocks() >>> a1 Matrix([ [1, 3], [y, z**2]]) >>> a2 Matrix([[x]]) >>> a3 Matrix([[0]]) )rrs rget_diag_blockszMatrixBase.get_diag_blockss0))++rct|dk(r|jSt|d}t|j|S)a(Return a matrix formed by joining args horizontally (i.e. by repeated application of row_join). Examples ======== >>> from sympy import Matrix, eye >>> Matrix.hstack(eye(2), 2*eye(2)) Matrix([ [1, 0, 2, 0], [0, 1, 0, 2]]) r)rrrrrow_joinrrklss rhstackzMatrixBase.hstacks9 t9>88: 47mcllD))rc 4|j|jz||zk7rtd||fz|jj Dcic]%\\}}}t ||jz|z||'}}}}|j |||Scc}}}w)aReshape the matrix. Total number of elements must remain the same. Examples ======== >>> from sympy import Matrix >>> m = Matrix(2, 3, lambda i, j: 1) >>> m Matrix([ [1, 1, 1], [1, 1, 1]]) >>> m.reshape(1, 6) Matrix([[1, 1, 1, 1, 1, 1]]) >>> m.reshape(3, 2) Matrix([ [1, 1], [1, 1], [1, 1]]) z Invalid reshape parameters %d %d)rr ValueErrortodokrdivmodr)rrrrrrrs rr+zMatrixBase.reshapes* 99tyy D4K /?4,NO O#zz|11355&1a!a kAot, 55""4s335s*Bc|dkr||jz }d|cxkr|jksntdj||j|S)zDelete the specified row.rzRow {} is out of range.)rrrr)rrs rrow_delzMatrixBase.row_delsP 7 499 CC#$))#6==cBC C!!#&&rc`|s|j|St|}|dkr|j|z}|dkrd}n||jkDr |j}|j|jk7r/t dj |j|j|j ||S)a}Insert one or more rows at the given row position. Examples ======== >>> from sympy import zeros, ones >>> M = zeros(3) >>> V = ones(1, 3) >>> M.row_insert(1, V) Matrix([ [0, 0, 0], [1, 1, 1], [0, 0, 0], [0, 0, 0]]) See Also ======== row col_insert rr)rr5rrr?rrrs r row_insertzMatrixBase.row_insert s.99U# #Sk 7))c/C 7C 499_))C 99 "N 5::.0 0$$S%00rc\|jdk(rE|j|jk7r,|j|jdgj|S|j|jk7r/t dj |j|j|j |S)a|Concatenates two matrices along self's last and rhs's first column Examples ======== >>> from sympy import zeros, ones >>> M = zeros(3) >>> V = ones(3, 1) >>> M.row_join(V) Matrix([ [0, 0, 0, 1], [0, 0, 0, 1], [0, 0, 0, 1]]) See Also ======== row col_join rr)rrrrr?rrrs rrzMatrixBase.row_join4s, 99>dii5::599UZZB/88? ? 99 "K 5::.0 0""5))rc jg}t|}|dkDrdn| }|rdn|} ||jk(s||jk(rn!|j|||f|dz }|dz }@|s8t t d|dd|jz d|jdz d|j dt||S)aReturns the kth diagonal of self. The main diagonal corresponds to `k=0`; diagonals above and below correspond to `k > 0` and `k < 0`, respectively. The values of `self[i, j]` for which `j - i = k`, are returned in order of increasing `i + j`, starting with `i + j = |k|`. Examples ======== >>> from sympy import Matrix >>> m = Matrix(3, 3, lambda i, j: j - i); m Matrix([ [ 0, 1, 2], [-1, 0, 1], [-2, -1, 0]]) >>> _.diagonal() Matrix([[0, 0, 0]]) >>> m.diagonal(1) Matrix([[1, 1]]) >>> m.diagonal(-2) Matrix([[-2]]) Even though the diagonal is returned as a Matrix, the element retrieval can be done with a single index: >>> Matrix.diag(1, 2, 3).diagonal()[1] # instead of [0, 1] 2 See Also ======== diag rr/z The z diagonal is out of range [, ])r5rrrrr6rr)rrrvrrs rrzMatrixBase.diagonalSsD 1IQAQBADII~dii IId1a4j ! FA FA  Z q499}dii!m)-./ /yyCGR((rc||ddfS)zElementary row selector. Examples ======== >>> from sympy import eye >>> eye(2).row(0) Matrix([[1, 0]]) See Also ======== col row_del row_join row_insert Nrrs rrzMatrixBase.rows$AqDzrc"|jS)zReturn the matrix as dictionary of keys. Examples ======== >>> from sympy import Matrix >>> M = Matrix.eye(3) >>> M.todok() {(0, 0): 1, (1, 1): 1, (2, 2): 1} )rrs rrzMatrixBase.todoks!!rc|jDcic]\}}||j|}}}|j|||Scc}}w)aCreate a matrix from a dictionary of keys. Examples ======== >>> from sympy import Matrix >>> d = {(0, 0): 1, (1, 2): 3, (2, 1): 4} >>> Matrix.from_dok(3, 3, d) Matrix([ [1, 0, 0], [0, 0, 3], [0, 4, 0]]) )rrr)rrrrijrs rfrom_dokzMatrixBase.from_doksJ58IIK@Sr3<<$$@@!!$c22AsAc|jsgS|js#t|jDcgc]}gc}S|jScc}w)a Return the Matrix as a nested Python list. Examples ======== >>> from sympy import Matrix, ones >>> m = Matrix(3, 3, range(9)) >>> m Matrix([ [0, 1, 2], [3, 4, 5], [6, 7, 8]]) >>> m.tolist() [[0, 1, 2], [3, 4, 5], [6, 7, 8]] >>> ones(3, 0).tolist() [[], [], []] When there are no rows then it will not be possible to tell how many columns were in the original matrix: >>> ones(0, 3).tolist() [] )rrrrrs rtolistzMatrixBase.tolistsE2yyIyy %dii 011B1 1  ""2s Aci}|j}t|D].\}}t|Dcic] \}}|s || }}}|s*|||<0|Scc}}w)a;Returns matrix as dict of dicts containing non-zero elements of the Matrix Examples ======== >>> from sympy import Matrix >>> A = Matrix([[0, 1],[0, 3]]) >>> A Matrix([ [0, 1], [0, 3]]) >>> A.todod() {0: {1: 1}, 1: {1: 3}} )r0r)rrowsdictMlolrMirMijrs rtododzMatrixBase.tododsd"xxzt_ "EAr(1" =fa1c6=C=!  ">s AAc"|jS)aReturn the Matrix converted into a one column matrix by stacking columns Examples ======== >>> from sympy import Matrix >>> m=Matrix([[1, 3], [2, 4]]) >>> m Matrix([ [1, 3], [2, 4]]) >>> m.vec() Matrix([ [1], [2], [3], [4]]) See Also ======== vech )rrs rveczMatrixBase.vecs0~~rc|jst|r|js td|j |S)a{Reshapes the matrix into a column vector by stacking the elements in the lower triangle. Parameters ========== diagonal : bool, optional If ``True``, it includes the diagonal elements. check_symmetry : bool, optional If ``True``, it checks whether the matrix is symmetric. Examples ======== >>> from sympy import Matrix >>> m=Matrix([[1, 2], [2, 3]]) >>> m Matrix([ [1, 2], [2, 3]]) >>> m.vech() Matrix([ [1], [2], [3]]) >>> m.vech(diagonal=False) Matrix([[2]]) Notes ===== This should work for symmetric matrices and ``vech`` can represent symmetric matrices in vector form with less size than ``vec``. See Also ======== vec zThe matrix is not symmetric.) is_squarer@ is_symmetricrr)rrcheck_symmetrys rvechzMatrixBase.vech s;T~~& & $"3"3"5;< <x((rct|dk(r|jSt|d}t|j|S)a:Return a matrix formed by joining args vertically (i.e. by repeated application of col_join). Examples ======== >>> from sympy import Matrix, eye >>> Matrix.vstack(eye(2), 2*eye(2)) Matrix([ [1, 0], [0, 1], [2, 0], [0, 2]]) r)rrrrrrs rvstackzMatrixBase.vstack<s9 t9>88: 47mcllD))rc4fd}|j|||S)zUdiag_dict is a defaultdict containing all the entries of the diagonal matrix.c||fSrr)rr diag_dicts rrz$MatrixBase._eval_diag..entryVsaV$ $rr)rrrrBrs ` r _eval_diagzMatrixBase._eval_diagRs %xxdE**rc|jg||zz}|jgt||z|dd|dz<|j|||dS)Nr/Fcopy)roneminr)rrrvalss r _eval_eyezMatrixBase._eval_eyeZsOz49%''3tT?2XtAvXxxdDux55ruppercP|dk(rfd}nfd}j|||S)NlowercR||k(rS|dz|k(r jSjSrrHrrrr eigenvalues rrz,MatrixBase._eval_jordan_block..entryc-6%%UaZ77NxxrcR||k(rS|dz|k(r jSjSrrPrQs rrz,MatrixBase._eval_jordan_block..entryjrSrrC)rsizerRbandrs` ` r_eval_jordan_blockzMatrixBase._eval_jordan_block`s) 7?  xxdE**rc4fd}j|||S)NcjSrrHrrrs rrz$MatrixBase._eval_ones..entryts 77NrrC)rrrrs` r _eval_oneszMatrixBase._eval_onesrs xxdE**rcN|j|||jg||zzdS)NFrF)rr)rrrs r _eval_zeroszMatrixBase._eval_zerosxs(xxdSXXJT $:xGGrc Nfd}jd|zdzd|zdz|}jtt| |dzd|z|jz}t jtt| |dzd|z|jz}||fS)NcD|dz|k(r jSjSrrPr[s rrz)MatrixBase._eval_wilkinson..entry~s !eqj377 6chh 6rr/T)unpack)rdiagrrTabs)rrrDwminuswpluss` r_eval_wilkinsonzMatrixBase._eval_wilkinson|s 7 HHQqS1WacAgu -$uaRQ/0>BQSSHCHHT%AE"23DHABQFLu}rF)strictrbrrc xddlm}ddlm}ddlm} |j d|} |r0t|dk(r"t|drt|d|s|d}tt} dx} } |D]}t|trj|r(||}|j\}}|j}n~| j|\}}}|j!D]\\}}}|| || z|| zf<g}n>t#|dr |j\}}|j}n|| | | f<| dz } | dz } t%|D]%\}}t%|D]\}}|| || z|| zf<'| |z } | |z } |||}}|| | }}n||n|}|| ks|| kr&t't)dj+| | ||| j-||| S) aX Returns a matrix with the specified diagonal. If matrices are passed, a block-diagonal matrix is created (i.e. the "direct sum" of the matrices). kwargs ====== rows : rows of the resulting matrix; computed if not given. cols : columns of the resulting matrix; computed if not given. cls : class for the resulting matrix unpack : bool which, when True (default), unpacks a single sequence rather than interpreting it as a Matrix. strict : bool which, when False (default), allows Matrices to have variable-length rows. Examples ======== >>> from sympy import Matrix >>> Matrix.diag(1, 2, 3) Matrix([ [1, 0, 0], [0, 2, 0], [0, 0, 3]]) The current default is to unpack a single sequence. If this is not desired, set `unpack=False` and it will be interpreted as a matrix. >>> Matrix.diag([1, 2, 3]) == Matrix.diag(1, 2, 3) True When more than one element is passed, each is interpreted as something to put on the diagonal. Lists are converted to matrices. Filling of the diagonal always continues from the bottom right hand corner of the previous item: this will create a block-diagonal matrix whether the matrices are square or not. >>> col = [1, 2, 3] >>> row = [[4, 5]] >>> Matrix.diag(col, row) Matrix([ [1, 0, 0], [2, 0, 0], [3, 0, 0], [0, 4, 5]]) When `unpack` is False, elements within a list need not all be of the same length. Setting `strict` to True would raise a ValueError for the following: >>> Matrix.diag([[1, 2, 3], [4, 5], [6]], unpack=False) Matrix([ [1, 2, 3], [4, 5, 0], [6, 0, 0]]) The type of the returned matrix can be set with the ``cls`` keyword. >>> from sympy import ImmutableMatrix >>> from sympy.utilities.misc import func_name >>> func_name(Matrix.diag(1, cls=ImmutableMatrix)) 'ImmutableDenseMatrix' A zero dimension matrix can be used to position the start of the filling at the start of an arbitrary row or column: >>> from sympy import ones >>> r2 = ones(0, 2) >>> Matrix.diag(r2, 1, 2) Matrix([ [0, 0, 1, 0], [0, 0, 0, 2]]) See Also ======== eye diagonal .dense.diag .expressions.blockmatrix.BlockMatrix .sparsetools.banded rrMatrix SparseMatrixrr/rzg The constructed matrix is {} x {} but a size of {} x {} was specified.)sympy.matrices.matrixbasersympy.matrices.densernsympy.matricesrpgetrr4rrrrrr0_handle_creation_inputsrhasattrrrr6rrD)rrjrbrrrrrrnrpklass diag_entriesrmaxcmaxmrr)rsmatrrmis rrczMatrixBase.diagsx 9// 5#& c$i1nT!W)=tAw 37D#3' t A!T"q A77DAq A!-!E!Ea!HJAq$%)ZZ\? A=> a$hD%9:?AG$ww1HHJ-. dD\*  "1 ;2%bM;DAq9:L!d(AH!56; ; AID AID5 6 <t$D <t$D<4TD $;$+Z)""(&tT4"@BC CdL99rc ||}|dks|dkrtdj|||jd|}t|t|}}|j ||S)zReturns an identity matrix. Parameters ========== rows : rows of the matrix cols : cols of the matrix (if None, cols=rows) kwargs ====== cls : class of the returned matrix r@Cannot create a {} x {} matrix. Both dimensions must be positiver)rrrtr5rKrrrrrws reyezMatrixBase.eyesn <D !8tax@@FtT@RT T 5#&D\6$>> from sympy import Matrix >>> from sympy.abc import x >>> Matrix.jordan_block(4, x) Matrix([ [x, 1, 0, 0], [0, x, 1, 0], [0, 0, x, 1], [0, 0, 0, x]]) Creating an alternative Jordan block matrix where `1` is on lower off-diagonal: >>> Matrix.jordan_block(4, x, band='lower') Matrix([ [x, 0, 0, 0], [1, x, 0, 0], [0, 1, x, 0], [0, 0, 1, x]]) Creating a Jordan block with keyword arguments >>> Matrix.jordan_block(size=4, eigenvalue=x) Matrix([ [x, 1, 0, 0], [0, x, 1, 0], [0, 0, x, 1], [0, 0, 0, x]]) References ========== .. [1] https://en.wikipedia.org/wiki/Jordan_matrix reigenvalNzMust supply an eigenvaluez=Inconsistent values are given: 'eigenval'={}, 'eigenvalue'={}zMust supply a matrix size)poprtrrr5rW)rrUrRrVrrwrs r jordan_blockzMatrixBase.jordan_block.s^ 5#&::j$/  ("289 9 8 #Xz4J(J""(&:">@ @#% <89 9d|''j$??rc ~||}|jd|}t|t|}}|j||S)zReturns a matrix of ones. Parameters ========== rows : rows of the matrix cols : cols of the matrix (if None, cols=rows) kwargs ====== cls : class of the returned matrix r)rtr5r\rs roneszMatrixBase.onessB <D 5#&D\6$>> from sympy import Matrix, Poly, Symbol, symbols >>> x = Symbol('x') >>> c0, c1, c2, c3, c4 = symbols('c0:5') >>> p = Poly(c0 + c1*x + c2*x**2 + c3*x**3 + c4*x**4 + x**5, x) >>> Matrix.companion(p) Matrix([ [0, 0, 0, 0, -c0], [1, 0, 0, 0, -c1], [0, 1, 0, 0, -c2], [0, 0, 1, 0, -c3], [0, 0, 0, 1, -c4]]) z{} must be a Poly instance.z{} must be a monic polynomial.z#{} must be a univariate polynomial.r/z${} must have degree not less than 1.cf|dz k(r d|z  S||dzk(r jSjS)Nr/rP)rrcoeffsrrUs rrz#MatrixBase.companion..entrys;D1H}rAv&a!eww88Or) rrr2rris_monic is_univariatedegree all_coeffsr)rpolyrrrUs` @@r companionzMatrixBase.companions&||D!$%:AA$GH H}}=DDTJK K!!5<>> from sympy import Matrix >>> wminus, wplus = Matrix.wilkinson(3) >>> wminus Matrix([ [-3, 1, 0, 0, 0, 0, 0], [ 1, -2, 1, 0, 0, 0, 0], [ 0, 1, -1, 1, 0, 0, 0], [ 0, 0, 1, 0, 1, 0, 0], [ 0, 0, 0, 1, 1, 1, 0], [ 0, 0, 0, 0, 1, 2, 1], [ 0, 0, 0, 0, 0, 1, 3]]) >>> wplus Matrix([ [3, 1, 0, 0, 0, 0, 0], [1, 2, 1, 0, 0, 0, 0], [0, 1, 1, 1, 0, 0, 0], [0, 0, 1, 0, 1, 0, 0], [0, 0, 0, 1, 1, 1, 0], [0, 0, 0, 0, 1, 2, 1], [0, 0, 0, 0, 0, 1, 3]]) References ========== .. [1] https://blogs.mathworks.com/cleve/2013/04/15/wilkinsons-matrices-2/ .. [2] J. H. Wilkinson, The Algebraic Eigenvalue Problem, Claredon Press, Oxford, 1965, 662 pp. r)rtr5ri)rrrrws r wilkinsonzMatrixBase.wilkinsons/H 5#& 1I$$Q''rcd|DS)Nc3FK|]}|tjus|ywr)r#Zeror s rrz/MatrixBase._eval_iter_values..s3a1AFF?3s!!rrs r_eval_iter_valueszMatrixBase._eval_iter_valuess 3433rc4t|jSr)r iter_valuesrs r _eval_valueszMatrixBase._eval_valuessD$$&''rc#Kt|jD]1}t|jD]}|||fs ||f|||ff3ywrrrrrrrs r_eval_iter_itemszMatrixBase._eval_iter_itemssXtyy! -A499% -1:a&$q!t*,, - -s 8A A c6|j}t||j|jzkr,t t j |rt j h}n t}|j|Dcgc]}|j|c}Scc}wr) valuesrrrrr#rsetunionatoms)rtypesrsrs r _eval_atomszMatrixBase._eval_atomssn v;TYY. .:affe3LAAqww&9Q%9::9s<Bcltjdt|jDS)Nc34K|]}|jywr) free_symbolsr s rrz0MatrixBase._eval_free_symbols..(sHQ^^H)rrrrs r_eval_free_symbolszMatrixBase._eval_free_symbols's&su{{HS5GHIIrcHtfd|jDS)Nc3<K|]}|jywr)has)rapatternss rrz'MatrixBase._eval_has..+s@5155(#@r)rrrrs `r _eval_haszMatrixBase._eval_has*s@T-=-=-?@@@rc,|jtSr)rrrs r_eval_is_symboliczMatrixBase._eval_is_symbolic-sxxrcXfdtfdjDS)Nc^||f||fjz jSr)adjointis_zerorrrsimpfuncs rz6MatrixBase._eval_is_matrix_hermitian..4s0HT!Q$Z$q!t*2D2D2F%FGOOrc3<K|]\\}}}||ywrr)rrrrherms rrz7MatrixBase._eval_is_matrix_hermitian..5G AaGrr8 iter_items)rrrs``@r_eval_is_matrix_hermitianz$MatrixBase._eval_is_matrix_hermitian3s OGT__5FGGGrcBtd|jDS)Nc34K|]}|jywrr)rrs rrz2MatrixBase._eval_is_zero_matrix..8s?q?r)r8rrs r_eval_is_zero_matrixzMatrixBase._eval_is_zero_matrix7s?D,<,<,>???rc|j|jfdtfd|jDS)Nc||k(r|uS|uSrr)rrrrHrs rrz.MatrixBase._eval_is_Identity..=sAFST rc3>K|]\\}}}|||ywrr)rrrridents rrz/MatrixBase._eval_is_Identity..>s!Eifq!a5Aq>E)rHrrr)rrrHrs @@@r_eval_is_IdentityzMatrixBase._eval_is_Identity:s2hhyyAE4??3DEEErcBtd|jDS)Nc3LK|]\\}}}||k7s|jywrrrrrrs rrz/MatrixBase._eval_is_diagonal..As"Pyv1qaP$$rrs r_eval_is_diagonalzMatrixBase._eval_is_diagonal@sPDOO4EPPPrcBtd|jDS)Nc3LK|]\\}}}||ks|jywrrrs rrz,MatrixBase._eval_is_lower..D"I!Q1q5199Irrrrs r_eval_is_lowerzMatrixBase._eval_is_lowerCIdoo.?IIIrcBtd|jDS)Nc3LK|]\\}}}||kDs|jywrrrs rrz,MatrixBase._eval_is_upper..Grrrrs r_eval_is_upperzMatrixBase._eval_is_upperFrrcBtd|jDS)Nc3RK|]\\}}}|dz|ks|j!ywr/Nrrs rrz7MatrixBase._eval_is_lower_hessenberg..Js&M!Q1q519199M''rrs r_eval_is_lower_hessenbergz$MatrixBase._eval_is_lower_hessenbergIMdoo.?MMMrcBtd|jDS)Nc3RK|]\\}}}||dzkDs|j!ywrrrs rrz7MatrixBase._eval_is_upper_hessenberg..Ms&M!Q1q1u9199Mrrrs r_eval_is_upper_hessenbergz$MatrixBase._eval_is_upper_hessenbergLrrcXfdtfdjDS)NcB||f||fz jSrrrs rrz/MatrixBase._eval_is_symmetric..Ps'8DAJad$;<DDrc3<K|]\\}}}||ywrr)rrrrsyms rrz0MatrixBase._eval_is_symmetric..QsFyv1qQFrr)rrrs``@r_eval_is_symmetriczMatrixBase._eval_is_symmetricOs DFDOO4EFFFrcXfdtfdjDS)NcB||f||fzjSrrrs rrz4MatrixBase._eval_is_anti_symmetric..Ts'HT!Q$Z$q!t*%<=EErc3<K|]\\}}}||ywrr)rrrrantis rrz5MatrixBase._eval_is_anti_symmetric..Urrr)rrrs``@r_eval_is_anti_symmetricz"MatrixBase._eval_is_anti_symmetricSs EGT__5FGGGrcdfdtjD}td|DS)Nc3,K|] }||f ywrrrrrs rrz5MatrixBase._has_positive_diagonals..XA1DAJAc34K|]}|jywr) is_positiverxs rrz5MatrixBase._has_positive_diagonals..YsA1Arrrr8rdiagonal_entriess` r_has_positive_diagonalsz"MatrixBase._has_positive_diagonalsWs)Adii0@AA0@AAArcdfdtjD}td|DS)Nc3,K|] }||f ywrrrs rrz8MatrixBase._has_nonnegative_diagonals..\rrc34K|]}|jywr)is_nonnegativers rrz8MatrixBase._has_nonnegative_diagonals..]sDa))Drrrs` r_has_nonnegative_diagonalsz%MatrixBase._has_nonnegative_diagonals[s)Adii0@AD3CDDDrcVtd|D}|stf}|j|S)avReturns the atoms that form the current object. Examples ======== >>> from sympy.abc import x, y >>> from sympy import Matrix >>> Matrix([[x]]) Matrix([[x]]) >>> _.atoms() {x} >>> Matrix([[x, y], [y, x]]) Matrix([ [x, y], [y, x]]) >>> _.atoms() {x, y} c3VK|]!}t|tr|n t|#ywr)rr)rts rrz#MatrixBase.atoms..ss"K:a.aDG;Ks'))tupler r)rrs rrzMatrixBase.atoms_s1(KUKKGEt''rc"|jS)zReturns the free symbols within the matrix. Examples ======== >>> from sympy.abc import x >>> from sympy import Matrix >>> Matrix([[x], [1]]).free_symbols {x} )rrs rrzMatrixBase.free_symbolsxs&&((rc |j|S)aTest whether any subexpression matches any of the patterns. Examples ======== >>> from sympy import Matrix, SparseMatrix, Float >>> from sympy.abc import x, y >>> A = Matrix(((1, x), (0.2, 3))) >>> B = SparseMatrix(((1, x), (0.2, 3))) >>> A.has(x) True >>> A.has(y) False >>> A.has(Float) True >>> B.has(x) True >>> B.has(y) False >>> B.has(Float) True )rrs rrzMatrixBase.hass.t~~x((rcn|}t|s |rtnd}|jsy|j|S)aCheck if matrix M is an antisymmetric matrix, that is, M is a square matrix with all M[i, j] == -M[j, i]. When ``simplify=True`` (default), the sum M[i, j] + M[j, i] is simplified before testing to see if it is zero. By default, the SymPy simplify function is used. To use a custom function set simplify to a function that accepts a single argument which returns a simplified expression. To skip simplification, set simplify to False but note that although this will be faster, it may induce false negatives. Examples ======== >>> from sympy import Matrix, symbols >>> m = Matrix(2, 2, [0, 1, -1, 0]) >>> m Matrix([ [ 0, 1], [-1, 0]]) >>> m.is_anti_symmetric() True >>> x, y = symbols('x y') >>> m = Matrix(2, 3, [0, 0, x, -y, 0, 0]) >>> m Matrix([ [ 0, 0, x], [-y, 0, 0]]) >>> m.is_anti_symmetric() False >>> from sympy.abc import x, y >>> m = Matrix(3, 3, [0, x**2 + 2*x + 1, y, ... -(x + 1)**2, 0, x*y, ... -y, -x*y, 0]) Simplification of matrix elements is done by default so even though two elements which should be equal and opposite would not pass an equality test, the matrix is still reported as anti-symmetric: >>> m[0, 1] == -m[1, 0] False >>> m.is_anti_symmetric() True If ``simplify=False`` is used for the case when a Matrix is already simplified, this will speed things up. Here, we see that without simplification the matrix does not appear anti-symmetric: >>> print(m.is_anti_symmetric(simplify=False)) None But if the matrix were already expanded, then it would appear anti-symmetric and simplification in the is_anti_symmetric routine is not needed: >>> m = m.expand() >>> m.is_anti_symmetric(simplify=False) True c|Srrrs rrz.MatrixBase.is_anti_symmetric..arF)r_utilities_simplifyr:rrsimplifyrs ris_anti_symmetriczMatrixBase.is_anti_symmetrics7~(#.6*KH~~++H55rc"|jS)a,Check if matrix is diagonal, that is matrix in which the entries outside the main diagonal are all zero. Examples ======== >>> from sympy import Matrix, diag >>> m = Matrix(2, 2, [1, 0, 0, 2]) >>> m Matrix([ [1, 0], [0, 2]]) >>> m.is_diagonal() True >>> m = Matrix(2, 2, [1, 1, 0, 2]) >>> m Matrix([ [1, 1], [0, 2]]) >>> m.is_diagonal() False >>> m = diag(1, 2, 3) >>> m Matrix([ [1, 0, 0], [0, 2, 0], [0, 0, 3]]) >>> m.is_diagonal() True See Also ======== is_lower is_upper sympy.matrices.matrixbase.MatrixBase.is_diagonalizable diagonalize )rrs r is_diagonalzMatrixBase.is_diagonalsR%%''rcjsyj\}fdtfdt|DS)aTests if the matrix is row weakly diagonally dominant. Explanation =========== A $n, n$ matrix $A$ is row weakly diagonally dominant if .. math:: \left|A_{i, i}\right| \ge \sum_{j = 0, j \neq i}^{n-1} \left|A_{i, j}\right| \quad {\text{for all }} i \in \{ 0, ..., n-1 \} Examples ======== >>> from sympy import Matrix >>> A = Matrix([[3, -2, 1], [1, -3, 2], [-1, 2, 4]]) >>> A.is_weakly_diagonally_dominant True >>> A = Matrix([[-2, 2, 1], [1, 3, 2], [1, -2, 0]]) >>> A.is_weakly_diagonally_dominant False >>> A = Matrix([[-4, 2, 1], [1, 6, 2], [1, -2, 5]]) >>> A.is_weakly_diagonally_dominant True Notes ===== If you want to test whether a matrix is column diagonally dominant, you can apply the test after transposing the matrix. Fcj}tD]}||k7s |t||fz }t||f|z jSr)rrrrr summationrrrs rtest_rowz:MatrixBase.is_weakly_diagonally_dominant..test_row:s[ I4[ 16T!Q$Z0I 1QT Oi/?? ?rc3.K|] }|ywrrrrrs rrz;MatrixBase.is_weakly_diagonally_dominant..A:!:r:rr8rrrrrs` @@ris_weakly_diagonally_dominantz(MatrixBase.is_weakly_diagonally_dominants:H~~ZZ d @:eDk:::rcjsyj\}fdtfdt|DS)aTests if the matrix is row strongly diagonally dominant. Explanation =========== A $n, n$ matrix $A$ is row strongly diagonally dominant if .. math:: \left|A_{i, i}\right| > \sum_{j = 0, j \neq i}^{n-1} \left|A_{i, j}\right| \quad {\text{for all }} i \in \{ 0, ..., n-1 \} Examples ======== >>> from sympy import Matrix >>> A = Matrix([[3, -2, 1], [1, -3, 2], [-1, 2, 4]]) >>> A.is_strongly_diagonally_dominant False >>> A = Matrix([[-2, 2, 1], [1, 3, 2], [1, -2, 0]]) >>> A.is_strongly_diagonally_dominant False >>> A = Matrix([[-4, 2, 1], [1, 6, 2], [1, -2, 5]]) >>> A.is_strongly_diagonally_dominant True Notes ===== If you want to test whether a matrix is column diagonally dominant, you can apply the test after transposing the matrix. Fcj}tD]}||k7s |t||fz }t||f|z jSr)rrrrrs rrz.test_rowls[ I4[ 16T!Q$Z0I 1QT Oi/<< .srrrrs` @@ris_strongly_diagonally_dominantz*MatrixBase.is_strongly_diagonally_dominantCs9H~~ZZ d =:eDk:::rcF|jsy|jtS)agChecks if the matrix is Hermitian. In a Hermitian matrix element i,j is the complex conjugate of element j,i. Examples ======== >>> from sympy import Matrix >>> from sympy import I >>> from sympy.abc import x >>> a = Matrix([[1, I], [-I, 1]]) >>> a Matrix([ [ 1, I], [-I, 1]]) >>> a.is_hermitian True >>> a[0, 0] = 2*I >>> a.is_hermitian False >>> a[0, 0] = x >>> a.is_hermitian >>> a[0, 1] = a[1, 0]*I >>> a.is_hermitian False F)r:rr rs r is_hermitianzMatrixBase.is_hermitianus :~~--.ABBrc<|jsy|jS)NF)r:rrs r is_IdentityzMatrixBase.is_Identitys~~%%''rc"|jS)a-Checks if the matrix is in the lower-Hessenberg form. The lower hessenberg matrix has zero entries above the first superdiagonal. Examples ======== >>> from sympy import Matrix >>> a = Matrix([[1, 2, 0, 0], [5, 2, 3, 0], [3, 4, 3, 7], [5, 6, 1, 1]]) >>> a Matrix([ [1, 2, 0, 0], [5, 2, 3, 0], [3, 4, 3, 7], [5, 6, 1, 1]]) >>> a.is_lower_hessenberg True See Also ======== is_upper_hessenberg is_lower )rrs ris_lower_hessenbergzMatrixBase.is_lower_hessenberg6--//rc"|jS)alCheck if matrix is a lower triangular matrix. True can be returned even if the matrix is not square. Examples ======== >>> from sympy import Matrix >>> m = Matrix(2, 2, [1, 0, 0, 1]) >>> m Matrix([ [1, 0], [0, 1]]) >>> m.is_lower True >>> m = Matrix(4, 3, [0, 0, 0, 2, 0, 0, 1, 4, 0, 6, 6, 5]) >>> m Matrix([ [0, 0, 0], [2, 0, 0], [1, 4, 0], [6, 6, 5]]) >>> m.is_lower True >>> from sympy.abc import x, y >>> m = Matrix(2, 2, [x**2 + y, y**2 + x, 0, x + y]) >>> m Matrix([ [x**2 + y, x + y**2], [ 0, x + y]]) >>> m.is_lower False See Also ======== is_upper is_diagonal is_lower_hessenberg )rrs ris_lowerzMatrixBase.is_lowersV""$$rc4|j|jk(S)a/Checks if a matrix is square. A matrix is square if the number of rows equals the number of columns. The empty matrix is square by definition, since the number of rows and the number of columns are both zero. Examples ======== >>> from sympy import Matrix >>> a = Matrix([[1, 2, 3], [4, 5, 6]]) >>> b = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> c = Matrix([]) >>> a.is_square False >>> b.is_square True >>> c.is_square True rrs rr:zMatrixBase.is_squares,yyDII%%rc"|jS)zChecks if any elements contain Symbols. Examples ======== >>> from sympy import Matrix >>> from sympy.abc import x, y >>> M = Matrix([[x, y], [1, 0]]) >>> M.is_symbolic() True )rrs r is_symboliczMatrixBase.is_symbolics%%''rcn|}t|s |rtnd}|jsy|j|S)aCheck if matrix is symmetric matrix, that is square matrix and is equal to its transpose. By default, simplifications occur before testing symmetry. They can be skipped using 'simplify=False'; while speeding things a bit, this may however induce false negatives. Examples ======== >>> from sympy import Matrix >>> m = Matrix(2, 2, [0, 1, 1, 2]) >>> m Matrix([ [0, 1], [1, 2]]) >>> m.is_symmetric() True >>> m = Matrix(2, 2, [0, 1, 2, 0]) >>> m Matrix([ [0, 1], [2, 0]]) >>> m.is_symmetric() False >>> m = Matrix(2, 3, [0, 0, 0, 0, 0, 0]) >>> m Matrix([ [0, 0, 0], [0, 0, 0]]) >>> m.is_symmetric() False >>> from sympy.abc import x, y >>> m = Matrix(3, 3, [1, x**2 + 2*x + 1, y, (x + 1)**2, 2, 0, y, 0, 3]) >>> m Matrix([ [ 1, x**2 + 2*x + 1, y], [(x + 1)**2, 2, 0], [ y, 0, 3]]) >>> m.is_symmetric() True If the matrix is already simplified, you may speed-up is_symmetric() test by using 'simplify=False'. >>> bool(m.is_symmetric(simplify=False)) False >>> m1 = m.expand() >>> m1.is_symmetric(simplify=False) True c|Srrr s rrz)MatrixBase.is_symmetric..Gr rF)rr r:rr s rr;zMatrixBase.is_symmetrics7n(#.6*KH~~&&x00rc"|jS)a(Checks if the matrix is the upper-Hessenberg form. The upper hessenberg matrix has zero entries below the first subdiagonal. Examples ======== >>> from sympy import Matrix >>> a = Matrix([[1, 4, 2, 3], [3, 4, 1, 7], [0, 2, 3, 4], [0, 0, 1, 3]]) >>> a Matrix([ [1, 4, 2, 3], [3, 4, 1, 7], [0, 2, 3, 4], [0, 0, 1, 3]]) >>> a.is_upper_hessenberg True See Also ======== is_lower_hessenberg is_upper )rrs ris_upper_hessenbergzMatrixBase.is_upper_hessenbergNr'rc"|jS)a$Check if matrix is an upper triangular matrix. True can be returned even if the matrix is not square. Examples ======== >>> from sympy import Matrix >>> m = Matrix(2, 2, [1, 0, 0, 1]) >>> m Matrix([ [1, 0], [0, 1]]) >>> m.is_upper True >>> m = Matrix(4, 3, [5, 1, 9, 0, 4, 6, 0, 0, 5, 0, 0, 0]) >>> m Matrix([ [5, 1, 9], [0, 4, 6], [0, 0, 5], [0, 0, 0]]) >>> m.is_upper True >>> m = Matrix(2, 3, [4, 2, 5, 6, 1, 1]) >>> m Matrix([ [4, 2, 5], [6, 1, 1]]) >>> m.is_upper False See Also ======== is_lower is_diagonal is_upper_hessenberg )rrs ris_upperzMatrixBase.is_upperksT""$$rc"|jS)a,Checks if a matrix is a zero matrix. A matrix is zero if every element is zero. A matrix need not be square to be considered zero. The empty matrix is zero by the principle of vacuous truth. For a matrix that may or may not be zero (e.g. contains a symbol), this will be None Examples ======== >>> from sympy import Matrix, zeros >>> from sympy.abc import x >>> a = Matrix([[0, 0], [0, 0]]) >>> b = zeros(3, 4) >>> c = Matrix([[0, 1], [0, 0]]) >>> d = Matrix([]) >>> e = Matrix([[x, 0], [0, 0]]) >>> a.is_zero_matrix True >>> b.is_zero_matrix True >>> c.is_zero_matrix False >>> d.is_zero_matrix True >>> e.is_zero_matrix )rrs ris_zero_matrixzMatrixBase.is_zero_matrixs:((**rc"|jS)aReturn non-zero values of self. Examples ======== >>> from sympy import Matrix >>> m = Matrix([[0, 1], [2, 3]]) >>> m.values() [1, 2, 3] See Also ======== iter_values tolist flat )rrs rrzMatrixBase.valuess$  ""rc"|jS)a Iterate over non-zero values of self. Examples ======== >>> from sympy import Matrix >>> m = Matrix([[0, 1], [2, 3]]) >>> list(m.iter_values()) [1, 2, 3] See Also ======== values )rrs rrzMatrixBase.iter_valuess"%%''rc"|jS)aCIterate over indices and values of nonzero items. Examples ======== >>> from sympy import Matrix >>> m = Matrix([[0, 1], [2, 3]]) >>> list(m.iter_items()) [((0, 1), 1), ((1, 0), 2), ((1, 1), 3)] See Also ======== iter_values todok )rrs rrzMatrixBase.iter_itemss"$$&&rcB|jjdS)Nc"|jSrrr s rrz*MatrixBase._eval_adjoint..s AIIKr) transpose applyfuncrs r _eval_adjointzMatrixBase._eval_adjoints~~))*?@@rc|j}|j|jz}|j}|jDcic] }||| }}t ||kr|t j x}t j urX|g|z}|jD]\\} } }|||| |z| z<|j|j|j|} | S|jD cic] \} }| || } } }|j|j|j| } | Scc}wcc}} wr) rrrrrr#rrrr.)rfrrUrrvalmapfzerorrroutr-fdoks r_eval_applyfunczMatrixBase._eval_applyfuncsyyyy"jjl#&::<0a!QqT'00 s8d?!AFF)!3AFF Bwt|H YY[ 1 A'-ay4!$ 1))DIItyy(;C  03yy{;eb!Bq M;D;-- 499d;C 1. s  rr<rs r_eval_conjugatezMatrixBase._eval_conjugates~~566rcvt|fd}jjj|S)Nc||fSrrrrmappingrs rrz,MatrixBase._eval_permute_cols..entrys71: & &rrrrrrpermrrPs` @r_eval_permute_colszMatrixBase._eval_permute_cols .t* 'yyDIIu55rcvt|fd}jjj|S)Nc||fSrrrOs rrz,MatrixBase._eval_permute_rows..entrys A & &rrQrRs` @r_eval_permute_rowszMatrixBase._eval_permute_rowsrUrcRtfdtjDS)Nc3,K|] }||f ywrrrs rrz)MatrixBase._eval_trace..s8!41:8r)sumrrrs`r _eval_tracezMatrixBase._eval_traces8uTYY'7888rcXjjjfdS)Nc||fSrrrrrs rrz,MatrixBase._eval_transpose..!sDAJr)rrrrs`r_eval_transposezMatrixBase._eval_transpose syyDII/FGGrc"|jS)z-Conjugate transpose or Hermitian conjugation.)r=rs rrzMatrixBase.adjoint#s!!##rcPt|s td|j|S)aLApply a function to each element of the matrix. Examples ======== >>> from sympy import Matrix >>> m = Matrix(2, 2, lambda i, j: i*2+j) >>> m Matrix([ [0, 1], [2, 3]]) >>> m.applyfunc(lambda i: 2*i) Matrix([ [0, 2], [4, 6]]) z`f` must be callable.)callabler rD)rr?s rr<zMatrixBase.applyfunc's(${34 4##A&&rc "|jS)z@Returns a tuple containing the (real, imaginary) part of matrix.)rF)rdeephintss r as_real_imagzMatrixBase.as_real_imag>s&&((rc"|jS)a#Return the by-element conjugation. Examples ======== >>> from sympy import SparseMatrix, I >>> a = SparseMatrix(((1, 2 + I), (3, 4), (I, -I))) >>> a Matrix([ [1, 2 + I], [3, 4], [I, -I]]) >>> a.C Matrix([ [ 1, 2 - I], [ 3, 4], [-I, I]]) See Also ======== transpose: Matrix transposition H: Hermite conjugation sympy.matrices.matrixbase.MatrixBase.D: Dirac conjugation )rLrs rrJzMatrixBase.conjugateCs4##%%rc ,|jfdS)Nc(|jdiSNr)doit)rrfs rrz!MatrixBase.doit..`srrK)rrfs `rrlzMatrixBase.doit_s~~788rcB||||||d|jfdS)&Apply evalf() to each element of self.)subsmaxnchoprjquadverbosec*|jfiSrevalf)rroptionss rrz"MatrixBase.evalf..fs(=W(=rrK) rrrorprqrjrrrsrws ` @rrvzMatrixBase.evalfbs(tD6w0~~=>>rc L |j f dS)a$Apply core.function.expand to each entry of the matrix. Examples ======== >>> from sympy.abc import x >>> from sympy import Matrix >>> Matrix(1, 1, [x*(x+1)]) Matrix([[x*(x + 1)]]) >>> _.expand() Matrix([[x**2 + x]]) c 8 |j fiSr)expand) rbasicrerfr'modulusmul multinomial power_base power_exps rrz#MatrixBase.expand..ws+ ':y#sK))rrK) rrer|rrr}r'r~r{rfs `````````rrzzMatrixBase.expandhs!~~ rc"|jS)aReturn Hermite conjugate. Examples ======== >>> from sympy import Matrix, I >>> m = Matrix((0, 1 + I, 2, 3)) >>> m Matrix([ [ 0], [1 + I], [ 2], [ 3]]) >>> m.H Matrix([[0, 1 - I, 2, 3]]) See Also ======== conjugate: By-element conjugation sympy.matrices.matrixbase.MatrixBase.D: Dirac conjugation r:rs rHz MatrixBase.H{s0||~rcddlm}|dk(rd}|dk(rd}|dk(rd}|d vrtd j||d vrtd j|t ||t fst d j||dk(r |jn |jtfdtt|Ds td|rFt ||s:t |dt r'|dk(rtt|}||dz}n ||dz}|dk(r|j|S|dk(r|j|Sy)a Permute the rows or columns of a matrix by the given list of swaps. Parameters ========== perm : Permutation, list, or list of lists A representation for the permutation. If it is ``Permutation``, it is used directly with some resizing with respect to the matrix size. If it is specified as list of lists, (e.g., ``[[0, 1], [0, 2]]``), then the permutation is formed from applying the product of cycles. The direction how the cyclic product is applied is described in below. If it is specified as a list, the list should represent an array form of a permutation. (e.g., ``[1, 2, 0]``) which would would form the swapping function `0 \mapsto 1, 1 \mapsto 2, 2\mapsto 0`. orientation : 'rows', 'cols' A flag to control whether to permute the rows or the columns direction : 'forward', 'backward' A flag to control whether to apply the permutations from the start of the list first, or from the back of the list first. For example, if the permutation specification is ``[[0, 1], [0, 2]]``, If the flag is set to ``'forward'``, the cycle would be formed as `0 \mapsto 2, 2 \mapsto 1, 1 \mapsto 0`. If the flag is set to ``'backward'``, the cycle would be formed as `0 \mapsto 1, 1 \mapsto 2, 2 \mapsto 0`. If the argument ``perm`` is not in a form of list of lists, this flag takes no effect. Examples ======== >>> from sympy import eye >>> M = eye(3) >>> M.permute([[0, 1], [0, 2]], orientation='rows', direction='forward') Matrix([ [0, 0, 1], [1, 0, 0], [0, 1, 0]]) >>> from sympy import eye >>> M = eye(3) >>> M.permute([[0, 1], [0, 2]], orientation='rows', direction='backward') Matrix([ [0, 1, 0], [0, 0, 1], [1, 0, 0]]) Notes ===== If a bijective function `\sigma : \mathbb{N}_0 \rightarrow \mathbb{N}_0` denotes the permutation. If the matrix `A` is the matrix to permute, represented as a horizontal or a vertical stack of vectors: .. math:: A = \begin{bmatrix} a_0 \\ a_1 \\ \vdots \\ a_{n-1} \end{bmatrix} = \begin{bmatrix} \alpha_0 & \alpha_1 & \cdots & \alpha_{n-1} \end{bmatrix} If the matrix `B` is the result, the permutation of matrix rows is defined as: .. math:: B := \begin{bmatrix} a_{\sigma(0)} \\ a_{\sigma(1)} \\ \vdots \\ a_{\sigma(n-1)} \end{bmatrix} And the permutation of matrix columns is defined as: .. math:: B := \begin{bmatrix} \alpha_{\sigma(0)} & \alpha_{\sigma(1)} & \cdots & \alpha_{\sigma(n-1)} \end{bmatrix} r) Permutationforwardsforward backwardsbackwardcolumnsr)rrz?direction='{}' is an invalid kwarg. Try 'forward' or 'backward'rz:orientation='{}' is an invalid kwarg. Try 'rows' or 'cols'zB{} must be a list, a list of lists, or a SymPy permutation object.rc3>K|]}d|cxkxrkncywrNr)rr max_indexs rrz%MatrixBase.permute.. sD11&Y&&Drz`swap` indices out of range.r/)rUN)sympy.combinatoricsrr rrrrrrrr3rrreversedrXrT)rrS orientation directionrrs @rpermutezMatrixBase.permutesnB 4  "!I  #"I ) # K 3 3::@&:KM M . .3396+3FH H$h 78117? ? "-!6DIIDII DT 0CDD;< <  45 tAw )I%HTN+t)A+6Dt)A+6D & **40 0 & **40 0 !rc*|j|d|S)zAlias for ``self.permute(swaps, orientation='cols', direction=direction)`` See Also ======== permute rrrrrswapsrs r permute_colszMatrixBase.permute_cols ||Ev|KKrc*|j|d|S)zAlias for ``self.permute(swaps, orientation='rows', direction=direction)`` See Also ======== permute rrrrs r permute_rowszMatrixBase.permute_rows) rrc,|jfdS)aApply refine to each element of the matrix. Examples ======== >>> from sympy import Symbol, Matrix, Abs, sqrt, Q >>> x = Symbol('x') >>> Matrix([[Abs(x)**2, sqrt(x**2)],[sqrt(x**2), Abs(x)**2]]) Matrix([ [ Abs(x)**2, sqrt(x**2)], [sqrt(x**2), Abs(x)**2]]) >>> _.refine(Q.real(x)) Matrix([ [ x**2, Abs(x)], [Abs(x), x**2]]) ct|Srr)r assumptionss rrz#MatrixBase.refine..F sq+(>rrK)rrs `rr zMatrixBase.refine4 s$~~>??rc |||d |ri fd}|j|}|fS|j fdS)aReplaces Function F in Matrix entries with Function G. Examples ======== >>> from sympy import symbols, Function, Matrix >>> F, G = symbols('F, G', cls=Function) >>> M = Matrix(2, 2, lambda i, j: F(i+j)) ; M Matrix([ [F(0), F(1)], [F(1), F(2)]]) >>> N = M.replace(F,G) >>> N Matrix([ [G(0), G(1)], [G(1), G(2)]]) )map simultaneousexactcX|jfi\}}j||Sr)replaceupdate)eijdijFGdrs rfuncz MatrixBase.replace..func_ s.&3;;q!6v6S  rc,|jfiSr)r)rrrrs rrz$MatrixBase.replace..h sIAIIa,Ef,ErrK) rrrrrrrrrrs `` @@rrzMatrixBase.replaceH sI$lUK A  t$Aa4K>>"EF Frc|dz}|dk(r|S|dk(r|dddddfjS|dk(r |ddddddfS|dk(r|dddddfjSy)aRotates Matrix by 90 degrees Parameters ========== k : int Specifies how many times the matrix is rotated by 90 degrees (clockwise when positive, counter-clockwise when negative). Examples ======== >>> from sympy import Matrix, symbols >>> A = Matrix(2, 2, symbols('a:d')) >>> A Matrix([ [a, b], [c, d]]) Rotating the matrix clockwise one time: >>> A.rot90(1) Matrix([ [c, a], [d, b]]) Rotating the matrix anticlockwise two times: >>> A.rot90(-2) Matrix([ [d, c], [b, a]]) rr/Nrrar)rd)rrmods rrot90zMatrixBase.rot90j s{Fc !8K !8"b>## # !8"dd # # !8DbD>## # rc ,|jfdS)aOApply simplify to each element of the matrix. Examples ======== >>> from sympy.abc import x, y >>> from sympy import SparseMatrix, sin, cos >>> SparseMatrix(1, 1, [x*sin(y)**2 + x*cos(y)**2]) Matrix([[x*sin(y)**2 + x*cos(y)**2]]) >>> _.simplify() Matrix([[x]]) c(|jdiSrkr rrs rrz%MatrixBase.simplify..   (>> from sympy.abc import x, y >>> from sympy import SparseMatrix, Matrix >>> SparseMatrix(1, 1, [x]) Matrix([[x]]) >>> _.subs(x, y) Matrix([[y]]) >>> Matrix(_).subs(y, x) Matrix([[x]]) r/rc(|jiSr)rorrrs rrz!MatrixBase.subs.. s(?(?r)rrdictriterr4rr<rrrs ``rrozMatrixBase.subs s[ t9>:d1gc{#CTRSW ^ijnopjq^raM#D~~?@@rch|j|jk7r t|jS)z Returns the trace of a square matrix i.e. the sum of the diagonal elements. Examples ======== >>> from sympy import Matrix >>> A = Matrix(2, 2, [1, 2, 3, 4]) >>> A.trace() 5 )rrr@r\rs rtracezMatrixBase.trace s, 99 !&( (!!rc"|jS)aa Returns the transpose of the matrix. Examples ======== >>> from sympy import Matrix >>> A = Matrix(2, 2, [1, 2, 3, 4]) >>> A.transpose() Matrix([ [1, 3], [2, 4]]) >>> from sympy import Matrix, I >>> m=Matrix(((1, 2+I), (3, 4))) >>> m Matrix([ [1, 2 + I], [3, 4]]) >>> m.transpose() Matrix([ [ 1, 3], [2 + I, 4]]) >>> m.T == m.transpose() True See Also ======== conjugate: By-element conjugation )r`rs rr;zMatrixBase.transpose sB##%%rc"|jS)zMatrix transposition)r;rs rrdz MatrixBase.T ~~rc"|jS)zBy-element conjugationrIrs rCz MatrixBase.C rrc&|j|i|S)rnrurs rrz MatrixBase.n stzz4*6**rc,|jfdS)akReturn a new matrix with xreplace applied to each entry. Examples ======== >>> from sympy.abc import x, y >>> from sympy import SparseMatrix, Matrix >>> SparseMatrix(1, 1, [x]) Matrix([[x]]) >>> _.xreplace({x: y}) Matrix([[y]]) >>> Matrix(_).xreplace({y: x}) Matrix([[x]]) c&|jSr)xreplace)rrules rrz%MatrixBase.xreplace.. s 4(8rrK)rrs `rrzMatrixBase.xreplace s~~899rc ,|jfdS)Nc(|jdiSrkrrs rrz+MatrixBase._eval_simplify.. rrrKrs `r_eval_simplifyzMatrixBase._eval_simplify s~~<==rc <ddlm|jfdS)Nr)trigsimpc|fiSrr)roptsrs rrz+MatrixBase._eval_trigsimp.. s(;d(;r)sympy.simplify.trigsimprr<)rrrs `@r_eval_trigsimpzMatrixBase._eval_trigsimp s4~~;<>> from sympy import ones >>> A = ones(4) >>> A.upper_triangular() Matrix([ [1, 1, 1, 1], [0, 1, 1, 1], [0, 0, 1, 1], [0, 0, 0, 1]]) >>> A.upper_triangular(2) Matrix([ [0, 0, 1, 1], [0, 0, 0, 1], [0, 0, 0, 0], [0, 0, 0, 0]]) >>> A.upper_triangular(-1) Matrix([ [1, 1, 1, 1], [1, 1, 1, 1], [0, 1, 1, 1], [0, 0, 1, 1]]) c:|z|kr||fSjSrrrrrrs rrz*MatrixBase.upper_triangular..entry9 $!"Q!41: : :rrrrrs`` rupper_triangularzMatrixBase.upper_triangular &B ;yyDIIu55rc`fd}jjj|S)aReturn the elements on and below the kth diagonal of a matrix. If k is not specified then simply returns lower-triangular portion of a matrix Examples ======== >>> from sympy import ones >>> A = ones(4) >>> A.lower_triangular() Matrix([ [1, 0, 0, 0], [1, 1, 0, 0], [1, 1, 1, 0], [1, 1, 1, 1]]) >>> A.lower_triangular(-2) Matrix([ [0, 0, 0, 0], [0, 0, 0, 0], [1, 0, 0, 0], [1, 1, 0, 0]]) >>> A.lower_triangular(1) Matrix([ [1, 1, 0, 0], [1, 1, 1, 0], [1, 1, 1, 1], [1, 1, 1, 1]]) c:|z|k\r||fSjSrrrs rrz*MatrixBase.lower_triangular..entry_ rrrrs`` rlower_triangularzMatrixBase.lower_triangular> rrcXjjjfdS)Nc$t||fSr)rr_s rrz&MatrixBase._eval_Abs..e sCQT Orrrs`r _eval_AbszMatrixBase._eval_Absd syyDII/KLLrc\jjjfdS)Nc"||f||fzSrrrrrrs rrz&MatrixBase._eval_add..i sd1a4j5A;&>rrrs``r _eval_addzMatrixBase._eval_addg s%yyDII>@ @rc`fd}jjj|S)NctjDcgc]}||f||fz}} t|Scc}w#ttf$rt d|cYSwxYw)Nc ||zSrr)rbs rrz.entry..t s 1q5r)rrr r r r)rrrr8rrs rrz*MatrixBase._eval_matrix_mul..entryl so16tyy1ABA4!9U1Q3Z'BCB 7Cy C|, 70#66  7s:?AArrrrs`` r_eval_matrix_mulzMatrixBase._eval_matrix_mulk s% 7yyEJJ66rc\jjjfdS)Nc"||f||fzSrrrs rrz9MatrixBase._eval_matrix_mul_elementwise..y sD1IeAaCjMatrixBase._eval_matrix_rmul..entry..} s&GuQqSz$qs)+Gr)r[rrrs``rrz+MatrixBase._eval_matrix_rmul..entry| sGU5::5FGG Grrrs`` r_eval_matrix_rmulzMatrixBase._eval_matrix_rmul{ s$ HyyTYY66rc|dk(r|S|dzdk(r||j|dz }}n|j|dzx}}|j|S)Nr/ra)_eval_pow_by_recursionmultiply)rnumrrs rrz!MatrixBase._eval_pow_by_recursion sX !8K 7a<44S1W=qA//q9 9Azz!}rcddlm}|jd}|j}| j dd}|||}|j |}|j |}t|D]}||||zz }||z}|S)Nr) linrec_coeffsr/)sympy.discrete.recurrencesrrcharpolyrrrr) rr&rrprnew_matansrs r_eval_pow_by_cayleyzMatrixBase._eval_pow_by_cayley s<jjm MMO""12&vs+((3-jjos A 6!9W$ $C tOG  rc|dgt|z}|dk(r|S|dzdk(r||j|dz |}}n|j|dz|x}}|j|d}t|}dg|z}t|D])}||rt ||d\||<||<"||||<+|j |j |j|S)NTr/ra)prevsimpF dotprodsimp)withsimp)r"_eval_pow_by_recursion_dotprodsimprrr0rrr) rrrrrr{lenmelemsrs rrz-MatrixBase._eval_pow_by_recursion_dotprodsimp s  vc$i'H !8K 7a<@@q%A'qA;;C1H%<' 'A 1% 0At t A{(4QqTD(I%a(1+Q4a  vvaffaffe,,rc\jjjfdS)Nc||fzSrrrs rrz-MatrixBase._eval_scalar_mul.. sD1IeOrrrs``r_eval_scalar_mulzMatrixBase._eval_scalar_mul yyDII/KLLrc\jjjfdS)Nc||fzSrrrs rrz.MatrixBase._eval_scalar_rmul.. sE$qs)Orrrs``r_eval_scalar_rmulzMatrixBase._eval_scalar_rmul rrc\jjjfdS)Nc&t||fSrrrs rrz&MatrixBase._eval_Mod.. sCQT E. s E rrKrs `r__mod__zMatrixBase.__mod__ s~~122r__rmul__c$|j|S)avReturn self*other where other is either a scalar or a matrix of compatible dimensions. Examples ======== >>> from sympy import Matrix >>> A = Matrix([[1, 2, 3], [4, 5, 6]]) >>> 2*A == A*2 == Matrix([[2, 4, 6], [8, 10, 12]]) True >>> B = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> A*B Matrix([ [30, 36, 42], [66, 81, 96]]) >>> B*A Traceback (most recent call last): ... ShapeError: Matrices size mismatch. >>> See Also ======== matrix_multiply_elementwise )rrs rr zMatrixBase.__mul__ s:}}U##rc td|}t||\}}}|dk(r |j|S|dk(r|j d|j dk7r&t d|j d|j d|j|}|r>|j|j|j|Dcgc] }t|c}}|StS#t$r tcYSwxYwcc}w) a\Same as __mul__() but with optional simplification. Parameters ========== dotprodsimp : bool, optional Specifies whether intermediate term algebraic simplification is used during matrix multiplications to control expression blowup and thus speed up calculation. Default is off. Fpossible_scalarrr/rrz * r) r<rrr rrr?rrrrr0rrr isimpboolrdr{es rrzMatrixBase.multiply s0{C *47eQ ! ! &,,U33+ zz!} A. #9$**S UV!WXX%%e,AFF166166Q+GLO+GHH" !! &%% &,HsC6C, C)(C)c|j|jk7r/tdj|j|j|j|S)aReturn the Hadamard product (elementwise product) of A and B Examples ======== >>> from sympy import Matrix >>> A = Matrix([[0, 1, 2], [3, 4, 5]]) >>> B = Matrix([[1, 10, 100], [100, 10, 1]]) >>> A.multiply_elementwise(B) Matrix([ [ 0, 10, 200], [300, 40, 5]]) See Also ======== sympy.matrices.matrixbase.MatrixBase.cross sympy.matrices.matrixbase.MatrixBase.dot multiply z!Matrix shapes must agree {} != {})rr?rrrs rmultiply_elementwisezMatrixBase.multiply_elementwise* sI* :: $@GG TYT_T_`a a0077rc$|jdS)Nr)rrs r__neg__zMatrixBase.__neg__D s$$R((r__rpow__c$|j|S)z$Return self**exp a scalar or symbol.)pow)rr&s r__pow__zMatrixBase.__pow__G sxx}rcl||dvr td|j|jk7r t|t dd}t j r(jjjdSdk(rSt dd}|2|r+jjjfdSjrHdzd k(r@jdk(rjd zggSd kr j|d k(r |S|d k(r0jrdzd k7r td jS|d k(r0jrdzd k7r tdjS|dk(r0jrdzd k7r tdjS|jrdzd k(rwjr t!jdk(r dkDr|St#ddrjSdkDrjSjS|r |Sd dlm}|S#t$r |d k(rY+wxYw#t$$r j&dusj(durYLwxYw)aReturn self**exp a scalar or symbol. Parameters ========== method : multiply, mulsimp, jordan, cayley If multiply then it returns exponentiation using recursion. If jordan then Jordan form exponentiation will be used. If cayley then the exponentiation is done using Cayley-Hamilton theorem. If mulsimp then the exponentiation is done using recursion with dotprodsimp. This specifies whether intermediate term algebraic simplification is used during naive matrix power to control expression blowup and thus speed up calculation. If None, then it heuristically decides which method to use. N)rmulsimpjordancayleyzNo such method_matrix_pow_by_jordan_blocksct||k(Sr)r)rrs rrz MatrixBase.pow..j ss16{rr/rc&||k(r ||fzSdS)Nrr)rrrr&s rrz MatrixBase.pow..p sa1fq1vs{RSrrr7r8z.cayley method is only valid for integer powersr6z/mulsimp method is only valid for integer powersrz0multiply method is only valid for integer powersraiTi'F)MatPow)r rrr@getattrrrr is_Numberinvr>rrrris_Floatrr<rA is_integerrsympy.matrices.expressionsr<)rr&method jordan_powrr<rs ` @rr3zMatrixBase.powN s&  &0["[,- - 99 !&( ( Q >E cl ;;66!&&!&&*BC C !8H1mT2  HJ66!&&!&&*ST T ==S1W\vv{vv!c {m,,QwdEEG X  !#& x ==C!GqL !QRR((- - y ==C!GqL !RSS77< < z !==C!GqL !STT++C0 0 ^ #'Q,||clvv{sV|!#&,T48;;C@@u,,S11//44  !#& 6a~Y X%& F,  >>U*c.@.@E.I/J  s$'I5J 5JJ &J32J3rc$|j|Sr)rrs rrzMatrixBase.__radd__ s||E""rr"cZt||\}}}|dk7rtS|j|Sr)rrr&r!s rrzMatrixBase.__rmatmul__ s1*47eQ ! !}}U##rr c$|j|Sr) rmultiplyrs rr&zMatrixBase.__rmul__ s~~e$$rc td|}t||\}}}|dk(r |j|S|dk(r}|j d|j dk7r t d|j|}|r>|j|j|j|Dcgc] }t|c}S|StS#t$r tcYSwxYwcc}w)a]Same as __rmul__() but with optional simplification. Parameters ========== dotprodsimp : bool, optional Specifies whether intermediate term algebraic simplification is used during matrix multiplications to control expression blowup and thus speed up calculation. Default is off. Fr)rrr/zMatrix size mismatch.) r<rr r rrr?rrrrr0r*s rrHzMatrixBase.rmultiply s0{C *47eQ ! ! &--e44+ zz!} A. !899&&u-Avvaffaff.J1|A.JKKH" ! &%% &/KsB<C <C C__sub__c| |zSrrrrs r__rsub__zMatrixBase.__rsub__ s{rrMc|| zSrrrLs rrJzMatrixBase.__sub__ sr{rct||SN) iszerofuncrLrrQs r_eval_det_bareisszMatrixBase._eval_det_bareiss sDZ88rct|Sr)rMrs r_eval_det_berkowitzzMatrixBase._eval_det_berkowitz s d##rct|||S)N)rQr)rP)rrQrs r _eval_det_luzMatrixBase._eval_det_lu st XFFrct|Sr)rNrs r_eval_det_birdzMatrixBase._eval_det_bird s rct|Sr)rOrs r_eval_det_laplacezMatrixBase._eval_det_laplace D!!rct|SrrKrs r_eval_determinantzMatrixBase._eval_determinant Dzrct||SNrC)rFrrCs radjugatezMatrixBase.adjugate sf--rlambdact|||S)N)rr )rGrrr s rrzMatrixBase.charpoly sX66rc t||||Src)rHrrrrCs rcofactorzMatrixBase.cofactor sq!F33rct||Src)rIres rcofactor_matrixzMatrixBase.cofactor_matrix sV44rct|||S)N)rCrQr_)rrCrQs rdetzMatrixBase.det sDJ??rct|Sr)rJrs rperzMatrixBase.per rarc t||||Src)rQrks rminorzMatrixBase.minor sdAq00rct|||Sr)rRrs rminor_submatrixzMatrixBase.minor_submatrix sa++rc t||||S)N)rQr  with_pivots)rT)rrQr rxs r echelon_formzMatrixBase.echelon_form" sTj8') )rct|Sr)rSrs r is_echelonzMatrixBase.is_echelon& s 4  rct|||SN)rQr )rUrrQr s rrankzMatrixBase.rank* sTj8DDrct|j||j|j|\}}|ddd|jf|dd|j dffS)aReturn reduced row-echelon form of matrix, matrix showing rhs after reduction steps. ``rhs`` must have the same number of rows as ``self``. Examples ======== >>> from sympy import Matrix, symbols >>> r1, r2 = symbols('r1 r2') >>> Matrix([[1, 1], [2, 1]]).rref_rhs(Matrix([r1, r2])) (Matrix([ [1, 0], [0, 1]]), Matrix([ [ -r1 + r2], [2*r1 - r2]])) N)rVrrrr)rrhsr)rs rrref_rhszMatrixBase.rref_rhs- sY"T[[txx ':C@A1JTYYJ1sxxij=!111rc"t|||||S)N)rQr pivotsnormalize_last)rV)rrQr rrs rrrefzMatrixBase.rrefA sTj8.: :rc|dvrtdj|||dk(r |jn |j}|dk(rM||n|}||tdj|d|cxkr|ksntdj|||d k(r||||hj dg}t |d kDr|||hj dg}t |d k7rtd j||\}}d|cxkr|ksntdj||d|cxkr|ksntdj|||d k(r||n|}||n|}|||td j|||k(rtdj|d|cxkr|ksntdj||d|cxkr|ks4ntdj||tdt |z|||||fS)zValidate the arguments for a row/column operation. ``error_str`` can be one of "row" or "col" depending on the arguments being parsed.)n->knn<->mn->n+kmzOUnknown {} operation '{}'. Valid col operations are 'n->kn', 'n<->m', 'n->n+km'rrNzEFor a {0} operation 'n->kn' you must provide the kwargs `{0}` and `k`rz#This matrix does not have a {} '{}'rrazIFor a {0} operation 'n<->m' you must provide the kwargs `{0}1` and `{0}2`rzPFor a {0} operation 'n->n+km' you must provide the kwargs `{0}`, `k`, and `{0}2`zAFor a {0} operation 'n->n+km' `{0}` and `{0}2` must be different.zinvalid operation %s)rrrr differencerrepr) roprrcol1col2 error_str self_colsrs r_normalize_op_argszMatrixBase._normalize_op_argsK sT 2 2??EviQS?TV V"+e!3DII  =#dC{ai "88>y8IKK'i' !F!M!MiY\!]^^ 7]D$'22D6:D4y1}T4(33TF;4yA~ "<? ?34%%rcdfd}jjj|S)Nc0|k(r ||fzS||fSrr)rrrrrs rrz.entry *Cx41:~%1: rr)rrrrs``` r"_eval_col_op_multiply_col_by_constz-MatrixBase._eval_col_op_multiply_col_by_const % yyDIIu55rcdfd}jjj|S)NcB|k(r|fS|k(r|fS||fSrr)rrrrrs rrz+MatrixBase._eval_col_op_swap..entry s;DyAtG}$dAtG}$1: rr)rrrrs``` r_eval_col_op_swapzMatrixBase._eval_col_op_swap %  yyDIIu55rchfd}jjj|S)Nc@|k(r||f|fzzS||fSrr)rrrrrrs rrz@MatrixBase._eval_col_op_add_multiple_to_other_col..entry s8CxAqDzAQW $5551: rr)rrrrrs```` r&_eval_col_op_add_multiple_to_other_colz1MatrixBase._eval_col_op_add_multiple_to_other_col % yyDIIu55rcdfd}jjj|S)NcB|k(r|fS|k(r|fS||fSrr)rrrow1row2rs rrz+MatrixBase._eval_row_op_swap..entry s;DyD!G}$dD!G}$1: rr)rrrrs``` r_eval_row_op_swapzMatrixBase._eval_row_op_swap rrcdfd}jjj|S)Nc0|k(r ||fzS||fSrr)rrrrrs rrz.entry rrr)rrrrs``` r"_eval_row_op_multiply_row_by_constz-MatrixBase._eval_row_op_multiply_row_by_const rrchfd}jjj|S)Nc@|k(r||f|fzzS||fSrr)rrrrrrs rrz@MatrixBase._eval_row_op_add_multiple_to_other_row..entry s8CxAqDzAT1W $5551: rr)rrrrrs```` r&_eval_row_op_add_multiple_to_other_rowz1MatrixBase._eval_row_op_add_multiple_to_other_row rrc|j|||||d\}}}}}|dk(r|j||S|dk(r|j||S|dk(r|j|||Sy)adPerforms the elementary column operation `op`. `op` may be one of * ``"n->kn"`` (column n goes to k*n) * ``"n<->m"`` (swap column n and column m) * ``"n->n+km"`` (column n goes to column n + k*column m) Parameters ========== op : string; the elementary row operation col : the column to apply the column operation k : the multiple to apply in the column operation col1 : one column of a column swap col2 : second column of a column swap or column "m" in the column operation "n->n+km" rrrrN)rrrr)rrrrrrs relementary_col_opzMatrixBase.elementary_col_op ("&!8!8S!T4QV!WCD$ =::3B B =))$5 5 ?>>sAtL L rc|j|||||d\}}}}}|dk(r|j||S|dk(r|j||S|dk(r|j|||Sy)a4Performs the elementary row operation `op`. `op` may be one of * ``"n->kn"`` (row n goes to k*n) * ``"n<->m"`` (swap row n and row m) * ``"n->n+km"`` (row n goes to row n + k*row m) Parameters ========== op : string; the elementary row operation row : the row to apply the row operation k : the multiple to apply in the row operation row1 : one row of a row swap row2 : second row of a row swap or row "m" in the row operation "n->n+km" rrrrN)rrrr)rrrrrrs relementary_row_opzMatrixBase.elementary_row_op rrct||SNr)rlrr s r columnspacezMatrixBase.columnspace sD844rct|||S)N)r rQ)rm)rr rQs r nullspacezMatrixBase.nullspace s$jIIrct||Sr)rnrs rrowspacezMatrixBase.rowspace s11rc t|g|i|Sr)ro)rvecsrs r orthogonalizezMatrixBase.orthogonalize sc3D3F33rc t|fd|i|S)Nerror_when_incomplete)rp)rrflagss r eigenvalszMatrixBase.eigenvals s$U6KUuUUrc  t|f||d|S)N)rrQ)rq)rrrQrs r eigenvectszMatrixBase.eigenvects s$407L%0).0 0rc t|fd|i|S)N reals_only)rt)rrrs ris_diagonalizablezMatrixBase.is_diagonalizable s!$H:HHHrc t||||S)N)rsort normalize)ru)rrrrs r diagonalizezMatrixBase.diagonalize sDZd#% %rct||SNrL)rrrrLs r bidiagonalizezMatrixBase.bidiagonalize sd%00rct||Sr)rsrs rbidiagonal_decompositionz#MatrixBase.bidiagonal_decomposition s(U;;rct|Sr)rvrs ris_positive_definitezMatrixBase.is_positive_definite $T**rct|Sr)rwrs ris_positive_semidefinitez#MatrixBase.is_positive_semidefinite (..rct|Sr)rxrs ris_negative_definitezMatrixBase.is_negative_definite rrct|Sr)ryrs ris_negative_semidefinitez#MatrixBase.is_negative_semidefinite" rrct|Sr)rzrs r is_indefinitezMatrixBase.is_indefinite& s d##rc t|fd|i|S)Ncalc_transform)r{)rrrs r jordan_formzMatrixBase.jordan_form* sDJJ6JJrc t|fi|Sr)r|rrs rleft_eigenvectszMatrixBase.left_eigenvects- s...rct|Sr)r}rs rsingular_valueszMatrixBase.singular_values0 %%r)evaluatecnddlm}||g|d|i}t|ts|r|j S|S)aeCalculate the derivative of each element in the matrix. Examples ======== >>> from sympy import Matrix >>> from sympy.abc import x, y >>> M = Matrix([[x, y], [1, 0]]) >>> M.diff(x) Matrix([ [1, 0], [0, 0]]) See Also ======== integrate limit r)ArrayDerivativer)$sympy.tensor.array.array_derivativesrrr as_mutable)rrrrrderivs rrzMatrixBase.diffB s<* I?t?h?$&8##% % rc,|jfdS)Nc&|jSrr)rargs rrz-MatrixBase._eval_derivative.._ ss rrK)rrs `r_eval_derivativezMatrixBase._eval_derivative^ s~~344rc0|jfdS)aIntegrate each element of the matrix. ``args`` will be passed to the ``integrate`` function. Examples ======== >>> from sympy import Matrix >>> from sympy.abc import x, y >>> M = Matrix([[x, y], [1, 0]]) >>> M.integrate((x, )) Matrix([ [x**2/2, x*y], [ x, 0]]) >>> M.integrate((x, 0, 2)) Matrix([ [2, 2*y], [2, 0]]) See Also ======== limit diff c(|jiSr) integraters rrz&MatrixBase.integrate..z s  T(DV(DrrKrs ``rrzMatrixBase.integratea s2~~DEErcddlm}t|sjjddk(rjd}n-jddk(rjd}n t djddk(rjd}n-jddk(rjd}n t dj||fdS)aCalculates the Jacobian matrix (derivative of a vector-valued function). Parameters ========== ``self`` : vector of expressions representing functions f_i(x_1, ..., x_n). X : set of x_i's in order, it can be a list or a Matrix Both ``self`` and X can be a row or a column matrix in any order (i.e., jacobian() should always work). Examples ======== >>> from sympy import sin, cos, Matrix >>> from sympy.abc import rho, phi >>> X = Matrix([rho*cos(phi), rho*sin(phi), rho**2]) >>> Y = Matrix([rho, phi]) >>> X.jacobian(Y) Matrix([ [cos(phi), -rho*sin(phi)], [sin(phi), rho*cos(phi)], [ 2*rho, 0]]) >>> X = Matrix([rho*cos(phi), rho*sin(phi)]) >>> X.jacobian(Y) Matrix([ [cos(phi), -rho*sin(phi)], [sin(phi), rho*cos(phi)]]) See Also ======== hessian wronskian rrlr/z)``self`` must be a row or a column matrixz"X must be a row or a column matrixc2|j|Srr)rrXrs rrz%MatrixBase.jacobian.. sDGLL1,>r)rqrrrrr )rrrr{rs`` rjacobianzMatrixBase.jacobian| sH 9!Z( ! A ::a=A  1 A ZZ]a  1 AGH H 771:? A WWQZ1_ A@A AyyA>??rc,|jfdS)aCalculate the limit of each element in the matrix. ``args`` will be passed to the ``limit`` function. Examples ======== >>> from sympy import Matrix >>> from sympy.abc import x, y >>> M = Matrix([[x, y], [1, 0]]) >>> M.limit(x, 2) Matrix([ [2, y], [1, 0]]) See Also ======== integrate diff c"|jSr)limit)rrs rrz"MatrixBase.limit.. srrK)rrs `rrzMatrixBase.limit s*~~677rc&|j|S)Nr )rris rberkowitz_charpolyzMatrixBase.berkowitz_charpoly s}}q}!!rc&|jdS)zeComputes determinant using Berkowitz method. See Also ======== det berkowitzrdrprs r berkowitz_detzMatrixBase.berkowitz_det sxx{x++rc &|jdi|S)z8Computes eigenvalues of a Matrix using Berkowitz method.r)rrs rberkowitz_eigenvalszMatrixBase.berkowitz_eigenvals st~~&&&rc|jg}}|jD]}|j||dz| }t|S)z1Computes principal minors using Berkowitz method.r)rHrrr)rsignminorsrs rberkowitz_minorszMatrixBase.berkowitz_minors sLxxfNN$ D MM$b/ *5D V}rcddlm}d}|s|S|js t||j}}dg|dz z}t |ddD]}||dz||dz }}||d|f |d||f} } |d|d|f|||f } }| g} t d|dz D]} | j || | zt| D]\} }| |zd| | <|j| g| z} t |D]} | d|| z dz|| d| f<|||dz <|j|j|d gg}t|D]\} }|j ||| z|ttt|zS)Nrr)r/r/rrarr) rsrr:r@rrrrrHrrr)rrberkAN transformsrrdrRrrrrBpolyss rrzMatrixBase.berkowitz s(K~~&( (TYY1SAE] q!R "AQ?AEqAa!eH9aAhqARaR!V9qAwhqACE1a!e_ + Qq\* +"%( )1E4=a )XXqME)E1X - !a%!),!"a% -!"Jq1u ' "*DHHqwh/01j) 'DAq LLU1X & 'eCu-...rc&|j|Src)rnres rcofactorMatrixzMatrixBase.cofactorMatrixs##6#22rct|SrrRrs r det_bareiszMatrixBase.det_bareisr]rc&|jdS)aCompute matrix determinant using LU decomposition. Note that this method fails if the LU decomposition itself fails. In particular, if the matrix has no inverse this method will fail. TODO: Implement algorithm for sparse matrices (SFF), http://www.eecis.udel.edu/~saunders/papers/sffge/it5.ps. See Also ======== det berkowitz_det lurdrrs rdet_LU_decompositionzMatrixBase.det_LU_decompositions$xxtx$$rc(|j||S)N)rUrR)r)rrrs r jordan_cellzMatrixBase.jordan_cell*s  aH ==rcL|j\}}||jfSr)rr)rcalc_transformationPJs r jordan_cellszMatrixBase.jordan_cells-s(!1!##%%%rc*|j|||Src)rtrks r minorEntryzMatrixBase.minorEntry1szz!Qvz..rc&|j||Sr)rvrs r minorMatrixzMatrixBase.minorMatrix4s##Aq))rc(|j|dS)zEPermute the rows of the matrix with the given permutation in reverse.rrrrrSs r permuteBkwdzMatrixBase.permuteBkwd7s   <>> from sympy import Matrix >>> m = Matrix([[0, 2], [3, 4]]) >>> m.flat() [0, 2, 3, 4] See Also ======== tolist values rrs rr)zMatrixBase.flatHs>$%*$))$4OqeDII>NOQT O OOOs(Ac@| |s tdddlm}|||S)Nz=Cannot implement copy=False when converting Matrix to ndarrayr/) matrix2numpy)dtype)r denser/)rr0rGr/s r __array__zMatrixBase.__array__\s&  D[\ \'D..rc4|j|jzS)zkReturn the number of elements of ``self``. Implemented mainly so bool(Matrix()) == False. rrs r__len__zMatrixBase.__len__bs yy499$$rc2ddlm}m}d}|j\}}|j }|Dcgc] }|| }}|D] }||| |j |j ||j |jScc}w)Nr)rc MutableMatrixc|jd}|d}|jr_|dk(r|jr ||z|d<n|jr |js t dt |D]}t |||d|f<nLt |D]>}t||}t|tr|j}|||z z|z|d|f<@t |D].}t d||z D]}||dz ||zdz f||||zf<0y)Nrrr/zANon-invertible matrix can only be raised to a nonnegative integer) rrrrArArr!r(r_eval_expand_func)jcrr lrbnrs rjordan_cell_powerzBMatrixBase._matrix_pow_by_jordan_blocks..jordan_cell_powerls! A3Ayy6a..dBsG,,1+;+;23vww"1X7"0A"61Q37q*A!!QB!"h/113!A#hrkBqsG * 1X /q!A#/A "AaC!AIBq1uI/ /r)rsrcr6rrrrr?) rrrcr6r<rrrrs rr9z'MatrixBase._matrix_pow_by_jordan_blocksis6 /*!1((* 2>?Q a(? ? &A a % &yyD,$78!%%'"$ $@sBctj|jvrd|jd|jdSdt |j zS)NMatrix(r&, [])z Matrix(%s))r#rrrrstrr0rs r__str__zMatrixBase.__str__s; 66TZZ +/99dii@ @c$++-000rc|s t}tj|jvrd|jd|j dS|jdk(rd|j |dzSd|j |dzS) Nr>r&r?r/z Matrix([%s])z, )rowsepz Matrix([ %s]))r%r#rrrrtable)rprinters r _format_strzMatrixBase._format_strsj lG 66TZZ +/99dii@ @ 99>!DJJwuJ$EE E$**WU*"CCCrct|}|Dcgc] }t|dr|jn|"c}tt t }Dcgc]}|j }}t |Dcgc]}|jd}}tfd|D} g} t|rg} t|D]Q\} } | j| ||  ddf|| xxdzcc<|| dk(s;|s>|jd|| <St | | k7rttd| j| t|r|j| Scc}wcc}wcc}w)aIReturn a matrix filled by the given matrices which are listed in order of appearance from left to right, top to bottom as they first appear in the matrix. They must fill the matrix completely. Examples ======== >>> from sympy import ones, Matrix >>> Matrix.irregular(3, ones(2,1), ones(3,3)*2, ones(2,2)*3, ... ones(1,1)*4, ones(2,2)*5, ones(1,2)*6, ones(1,2)*7) Matrix([ [1, 2, 2, 2, 3, 3], [1, 2, 2, 2, 3, 3], [4, 2, 2, 2, 5, 5], [6, 6, 7, 7, 5, 5]]) as_explicitrc3<K|]}|jywrr)rrrs rrz'MatrixBase.irregular..s-1Q499-rNr/zf Matrices provided do not appear to fill the space completely.)r5rvrHrrrrrr[rrextendrr6rr)rntopmatricesrrqdatractiverrr)rrrs @r irregularzMatrixBase.irregulars`&d| !(= 9Q]]_q @  s1v  !!qvv!!$)$K0q!%%(00-f--#hA!&) )11s1vgqj)*A! q6Q;1 !aF1I  ) 1v~ --".// KKN#hxx~' "0s%E(E-<E2c|j}t|jdk(rO|jd|jd}}|jDcgc]}|j |}}|||fSt|jdk(r0|Dcgc]}|j |}}|jdd|fSt dcc}wcc}w)Nrarr/z&SymPy supports just 1D and 2D matrices)r2rrravelrr)rrarrrrr flat_lists r_handle_ndarrayzMatrixBase._handle_ndarrays mmo syy>Q 1syy|$D25))+>Qa>I>y( ( ^q 256Qa6I699Q<I- -%8: : ?7s C Ccddlm}ddlmddlmd}t |dk(r t|d|r9|dj|djt|djfSt|dtr0|dj|dj|djfSt|dtrM|djr>|dj|dj|dj!jfSt|dt"j$r<|d}|Dcgc]}|j'|}}|j|j|fSt)|ddr|j+|dSt-|drt|dt.st1|d}fdfd |j3d d r6fd fd }t|t0t4fr|D cgc] } ||  }} t |dk(rdx} } g}n^t7fd|Dr?t |ddk(r.t7d|Ds t9dt |} d} g}n t;fd|Ds1|D cgc]} |j'| }} t |} | rdnd} nʼnrt7fd|Dr|D chc]$} t;| j<s| j&} } | rht | dk7r t9d|D cgc] } | jD] }|D]}| "}}} }| j?} t || z} ndx} } g}nrEt;fd|Dr0tA} g}|D]} | rg|jC| jDcgc] }|D]}| c}}t;| j<r| jE| jnu| rK| rk| jEt | |jC| Dcgc]}|j'|c}n"| jEd|jG| t | dkDst9d| j?} t || z} ng}tA} dx} } |D]E} t-| stI| dds t9dt)| drd| j<vrBrt7fd| Drp|jK| D cgc]} | jLc} \}}}tO||g}tQ|D cgc]}tQ|D] } || | c} }}||}}n>d}tI| ddrd}| g}n)t | }| D cgc]} |j'| }} | jE|t | dkDr t9d|jC|| |z } H| r| j?nd} nUt |dk(r2tS|d} tS|d} | dks| dkrt9djU| | t |dk(rt|dtVrt|d}g}tQ| D]^} |jCtQ| Dcgc]8}|j'||j'| |j'|:c}`npt |dk(rbt-|drT|d}t || | zk7r t9d|D cgc]} |j'| }} nt |dk(rdx} } g}|tYt[d  |fScc}wcc} wcc} wcc} wcc}}} wcc}}wcc}wcc} wcc} }wcc} wcc}wcc} w)a}Return the number of rows, cols and flat matrix elements. Examples ======== >>> from sympy import Matrix, I Matrix can be constructed as follows: * from a nested list of iterables >>> Matrix( ((1, 2+I), (3, 4)) ) Matrix([ [1, 2 + I], [3, 4]]) * from un-nested iterable (interpreted as a column) >>> Matrix( [1, 2] ) Matrix([ [1], [2]]) * from un-nested iterable with dimensions >>> Matrix(1, 2, [1, 2] ) Matrix([[1, 2]]) * from no arguments (a 0 x 0 matrix) >>> Matrix() Matrix(0, 0, []) * from a rule >>> Matrix(2, 2, lambda i, j: i/(j + 1) ) Matrix([ [0, 0], [1, 1/2]]) See Also ======== irregular - filling a matrix with irregular blocks rro) MatrixSymbol) BlockMatrixNr/r2cLt|txrxst|fSr)rr)rrXrWrs rrz4MatrixBase._handle_creation_inputs.."s+*Q ";#LJ 1{L.I Jrc0t|xr | Sr)r4)rismats rrz4MatrixBase._handle_creation_inputs..$s A ?uQx<rrTct|r|jSt|r,td|jDr|jS|S)zmake Block and Symbol explicitc34K|]}|jywr) is_Integer)rrs rrzLMatrixBase._handle_creation_inputs..make_explicit...s@_RS@_r)rrHrr)rrXrWs r make_explicitz9MatrixBase._handle_creation_inputs..make_explicit*sH%a5#$==?2'<8S@_WXW^W^@_=_#$==?2#$Hrcvt|ttfr|Dcgc] }| c}S|Scc}wr)rrr)rrr_s rmake_explicit_rowz=MatrixBase._handle_creation_inputs..make_explicit_row3s8%cD%=9>A#BM!$4#BB#0#55$Cs6c3.K|] }|ywrr)rrraws rrz5MatrixBase._handle_creation_inputs..@s-AQ-rc38K|]}t|dk(ywr)rr s rrz5MatrixBase._handle_creation_inputs..As8qs1v{8zmismatched dimensionsc3BK|]}|xs|ywrr)rrr[rcs rrz5MatrixBase._handle_creation_inputs..Fs!=ASV/uQx/=sc3.K|] }|ywrrrrr[s rrz5MatrixBase._handle_creation_inputs..K%<1eAh%.Wrir is_MatrixFzexpecting list of listsc3.K|] }|ywrrrhs rrz5MatrixBase._handle_creation_inputs..{s+BE!H+Brrrraz+List length should be equal to rows*columnszf Data type not understood; expecting list of lists or lists of values.).rsrp"sympy.matrices.expressions.matexprrW&sympy.matrices.expressions.blockmatrixrXrrrrr3r0rr)r rkrHmpmatrixrrvrUr4DeferredVectorrrtrrrrrrrrJaddrr=rurdr+rr5rr*r r6)rrrrprTrrrNrarrrrncolr)rrrr-rflatTrdr)rrXrWrr[r_rcs @@@@@@rruz"MatrixBase._handle_creation_inputssC\ 0CF t9>$q'<0Aw||T!W\\747>>;K3LLLDGZ0Aw||T!W\\47<<>AADGU+Q0A0AAw||T!W\\473F3F3H3M3M3OOODGRYY/G678S\\!_8 8vvqvvy00a+.**4733T!W%&tAw?47mL?!::j$7%6"#e}5ADE#05EEs8q="#OD4 "I---#c!f+2B8C88()@AAs8DD "I===:= >Qa >I >y>D $1!D#%<%<"<,/@q3qww",-D"EE03$S$S1QXXZ$SQR$SAQ$SQ$SQ$S $S#xxz"9~t3&'t$& #%<%<"<5D "I F 8%,,,-HHJ Bq B1 B BD"177| $ 0 V $Q 0 ) 0 0Q1Or#,,r2B1O P HHQK%,,Q/t9q=",-D"EEF 88:Dy>4/D !#I5D"#OD4""*3/$+Ce$D",-F"GG"3 4 CII~ (#+Bc+B(B*-*E*E.1 2 2+4KAq% 's 3A27( MQE!H Mq1a M M!#$aqA !A&sK?$%(+u$'HAD'EA Q'E'E t9q=",-D"EE!((. 9":*.488:1D Y!^$q'?D$q'?Dax4!8 "DDJF4QUDVXX4yA~*T!Wh"?!W t0A$$"'+/ba#,,q/&JK/00 TaKQ$8 G y>TD[0$EGG6?@S\\!_@ @Y!^OD4I  J('() )T9$$9HF!? A%T!C 2P4!3!N(F,/AsN;^'^,^1!^6<^6-%^; _ _ ?_ 8__=_ _"cddlm}t|t}|j |x\}}}t|t }t|tst|trQ|r|j ||yt|tst|r|j||ytd|z|s%t|tst|r ||}d}|r|r9tt||jtt||jf}n2t|||jzt|||jzf}|j ||y|||j|fS)amHelper to set value at location given by key. Examples ======== >>> from sympy import Matrix, I, zeros, ones >>> m = Matrix(((1, 2+I), (3, 4))) >>> m Matrix([ [1, 2 + I], [3, 4]]) >>> m[1, 0] = 9 >>> m Matrix([ [1, 2 + I], [9, 4]]) >>> m[1, 0] = [[0, 1]] To replace row r you assign to position r*m where m is the number of columns: >>> M = zeros(4) >>> m = M.cols >>> M[3*m] = ones(1, m)*2; M Matrix([ [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [2, 2, 2, 2]]) And to replace column c you can assign to position c: >>> M[2] = ones(m, 1)*4; M Matrix([ [0, 0, 4, 0], [0, 0, 4, 0], [0, 0, 4, 0], [2, 2, 4, 2]]) r/rmNzunexpected value: %sT)r1rnrslicekey2ijr copyin_matrixr,r4 copyin_listrr rrrr)rrvaluernis_slicerris_mats r_setitemzMatrixBase._setitemsDP "c5)[[%%1sE:. a :a#7""3.eT*{5/A  e,3e;< <"5%0[5Gu  &DII"67 &DII"679C!A N3 A N35C""3. !T]]5111rc ||zS)zReturn self + b.rrrs rrrzMatrixBase.adds axrc`|s |jS|j}t|t|z S)a{Returns the condition number of a matrix. This is the maximum singular value divided by the minimum singular value Examples ======== >>> from sympy import Matrix, S >>> A = Matrix([[1, 0, 0], [0, 10, 0], [0, 0, S.One/10]]) >>> A.condition_number() 100 See Also ======== singular_values )rrrr)rsingularvaluess rcondition_numberzMatrixBase.condition_numbers4&99 --/N#c>&:::rcl|j|j|j|jS)z Returns the copy of a matrix. Examples ======== >>> from sympy import Matrix >>> A = Matrix(2, 2, [1, 2, 3, 4]) >>> A.copy() Matrix([ [1, 2], [3, 4]]) )rrrr)rs rrGzMatrixBase.copys%yyDIItyy{;;rc <ddlm}t|t|fs$t dj |t ||j|jz|j|jzcxk(rdk(s?ntd|j|jfd|j|jf|j|j|j|d|dz|d|dzz |d|dz|d|dzz |d|dz|d|dzz fS) a- Return the cross product of ``self`` and ``b`` relaxing the condition of compatible dimensions: if each has 3 elements, a matrix of the same type and shape as ``self`` will be returned. If ``b`` has the same shape as ``self`` then common identities for the cross product (like `a \times b = - b \times a`) will hold. Parameters ========== b : 3x1 or 1x3 Matrix See Also ======== dot hat vee multiply multiply_elementwise r) MatrixExprz{} must be a Matrix, not {}.rz(Dimensions incorrect for cross product: z x r/ra) rmrrrr rrrrr?r)rrrs rcrosszMatrixBase.cross+s* B!j*56.55aaAC C DII%!&&=A=#yy$))4qvvqvv6FHI I99TYY a1Q4$q'AaD.0a1Q4$q'AaD.0a1Q4$q'AaD.0434 4rc |jdk7r!tdt|jz|\}}}|jddd| ||d| | |df S)a Return the skew-symmetric matrix representing the cross product, so that ``self.hat() * b`` is equivalent to ``self.cross(b)``. Examples ======== Calling ``hat`` creates a skew-symmetric 3x3 Matrix from a 3x1 Matrix: >>> from sympy import Matrix >>> a = Matrix([1, 2, 3]) >>> a.hat() Matrix([ [ 0, -3, 2], [ 3, 0, -1], [-2, 1, 0]]) Multiplying it with another 3x1 Matrix calculates the cross product: >>> b = Matrix([3, 2, 1]) >>> a.hat() * b Matrix([ [-4], [ 8], [-4]]) Which is equivalent to calling the ``cross`` method: >>> a.cross(b) Matrix([ [-4], [ 8], [-4]]) See Also ======== dot cross vee multiply multiply_elementwise )rr/z+Dimensions incorrect, expected (3, 1), got rr)rr?r@r)rryzs rhatzMatrixBase.hatOssZ :: J _-. .GAq!99QQBQQ$ rc|jdk7r!tdt|jz|js t d|j dd|d|d|dfS) ap Return a 3x1 vector from a skew-symmetric matrix representing the cross product, so that ``self * b`` is equivalent to ``self.vee().cross(b)``. Examples ======== Calling ``vee`` creates a vector from a skew-symmetric Matrix: >>> from sympy import Matrix >>> A = Matrix([[0, -3, 2], [3, 0, -1], [-2, 1, 0]]) >>> a = A.vee() >>> a Matrix([ [1], [2], [3]]) Calculating the matrix product of the original matrix with a vector is equivalent to a cross product: >>> b = Matrix([3, 2, 1]) >>> A * b Matrix([ [-4], [ 8], [-4]]) >>> a.cross(b) Matrix([ [-4], [ 8], [-4]]) ``vee`` can also be used to retrieve angular velocity expressions. Defining a rotation matrix: >>> from sympy import rot_ccw_axis3, trigsimp >>> from sympy.physics.mechanics import dynamicsymbols >>> theta = dynamicsymbols('theta') >>> R = rot_ccw_axis3(theta) >>> R Matrix([ [cos(theta(t)), -sin(theta(t)), 0], [sin(theta(t)), cos(theta(t)), 0], [ 0, 0, 1]]) We can retrieve the angular velocity: >>> Omega = R.T * R.diff() >>> Omega = trigsimp(Omega) >>> Omega.vee() Matrix([ [ 0], [ 0], [Derivative(theta(t), t)]]) See Also ======== dot cross hat multiply multiply_elementwise )rrz+Dimensions incorrect, expected (3, 3), got zMatrix is not skew-symmetricrr/)rar/)rra)r/r)rr?r@rrrrs rveezMatrixBase.veesxH :: J _-. .'');< <99Qddd$ rcbddlm}|jdk7rt|j|dzS)aReturn Dirac conjugate (if ``self.rows == 4``). Examples ======== >>> from sympy import Matrix, I, eye >>> m = Matrix((0, 1 + I, 2, 3)) >>> m.D Matrix([[0, 1 - I, -2, -3]]) >>> m = (eye(4) + I*eye(4)) >>> m[0, 3] = 2 >>> m.D Matrix([ [1 - I, 0, 0, 0], [ 0, 1 - I, 0, 0], [ 0, 0, -1 + I, 0], [ 2, 0, 0, -1 + I]]) If the matrix does not have 4 rows an AttributeError will be raised because this property is only defined for matrices with 4 rows. >>> Matrix(eye(2)).D Traceback (most recent call last): ... AttributeError: Matrix has no attribute D. See Also ======== sympy.matrices.matrixbase.MatrixBase.conjugate: By-element conjugation sympy.matrices.matrixbase.MatrixBase.H: Hermite conjugation r)mgammar)sympy.physics.matricesrrAttributeErrorr)rrs rrfz MatrixBase.Ds.D 2 99> ! vvq !!rcFddlm}t|tst |rkt ||j k7r>> from sympy import Matrix >>> M = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) >>> v = Matrix([1, 1, 1]) >>> M.row(0).dot(v) 6 >>> M.col(0).dot(v) 12 >>> v = [3, 2, 1] >>> M.row(0).dot(v) 10 >>> from sympy import I >>> q = Matrix([1*I, 1*I, 1*I]) >>> q.dot(q, hermitian=False) -3 >>> q.dot(q, hermitian=True) 3 >>> q1 = Matrix([1, 1, 1*I]) >>> q.dot(q1, hermitian=True, conjugate_convention="maths") 1 - 2*I >>> q.dot(q1, hermitian=True, conjugate_convention="physics") 1 + 2*I See Also ======== cross multiply multiply_elementwise r/rmz&Dimensions incorrect for dot product: r&z2`b` must be an ordered iterable or Matrix, not %s.Tmaths)rleftmath)physicsrightzUnknown conjugate_convention was entered. conjugate_convention must be one of the following: math, maths, left, physics or right.r)r1rnrrr4rrrr?rdotr rr+rJr)rr hermitianconjugate_conventionrnrrs rrzMatrixBase.dotsh "!Z(1~q6TYY&3q6TYY+>$ JJA011xxq **HG TZZ Qagg%5  t9A BF**aggVX X H 99A ++a#C 77q!f  !QA + 0AI -5#*  #'@@mmo%)==KKM "TUUa|rc ddlm}|ddddf|j}}||}|jr|St d|D]N}t d|D]=}d}t d|D]}|t ||d||d|fzz }||||f<| |||f<?Pt d|D]S} d}t d|D],} t d|D]} |t d| | | || | fzz }.|dz}| |d| f<||| df<U|S)aReturns the dual of a matrix. A dual of a matrix is: ``(1/2)*levicivita(i, j, k, l)*M(k, l)`` summed over indices `k` and `l` Since the levicivita method is anti_symmetric for any pairwise exchange of indices, the dual of a symmetric matrix is the zero matrix. Strictly speaking the dual defined here assumes that the 'matrix' `M` is a contravariant anti_symmetric second rank tensor, so that the dual is a covariant second rank tensor. rrNr/ra)rsrrr;rr") rrrrworkrracumrr:rrs rdualzMatrixBase.dualfsN )AqDz4991Qx    Kq! #A1a[ #q!=AJq!Q2Qq!tW<>> from sympy import Symbol, Matrix >>> l = Symbol('lamda') A trivial example of 1*1 Jordan block: >>> m = Matrix.jordan_block(1, l) >>> m._eval_matrix_exp_jblock() Matrix([[exp(lamda)]]) An example of 3*3 Jordan block: >>> m = Matrix.jordan_block(3, l) >>> m._eval_matrix_exp_jblock() Matrix([ [exp(lamda), exp(lamda), exp(lamda)/2], [ 0, exp(lamda), exp(lamda)], [ 0, 0, exp(lamda)]]) References ========== .. [1] https://en.wikipedia.org/wiki/Matrix_function#Jordan_decomposition rr/banded)rr&rr) sparsetoolsrr)rrUr:exp_lrbandsrs r_eval_matrix_exp_jblockz"MatrixBase._eval_matrix_exp_jblocksb<yy JA27+>QEIaL((>>'~~fT5122?sA ct|t|}}|jst|jst dj |||j vrt dj ||||j vrt dj |||j}t|j}i}|}t|dz D]}t||}|||dz<|jd}|j|} |j|d} d} |D]X}||} |j||| | <| | jr-| | j st dj || | d} t|D]}| | | |f<| |z} | dkDrt|Dcgc]}d}}d}| dkDr| dz} | dz} ||j||}|jr*|j st dj ||||| | <t|D]E}||z dzdkr d| | |f<d||<||||z dzz||<||t#|||z z| | |f<G|dz }| dkDr| dz } [| j%| }|j|}|j'|}t|D]}||||zz}||z}|Scc}w)a Computes f(A) where A is a Square Matrix and f is an analytic function. Examples ======== >>> from sympy import Symbol, Matrix, S, log >>> x = Symbol('x') >>> m = Matrix([[S(5)/4, S(3)/4], [S(3)/4, S(5)/4]]) >>> f = log(x) >>> m.analytic_func(f, x) Matrix([ [ 0, log(2)], [log(2), 0]]) Parameters ========== f : Expr Analytic Function x : Symbol parameter of f z{} must be a symbol.z{} must be a parameter of {}.z!{} must not be a parameter of {}.r/rz_Cannot evaluate the function because the function {} is not analytic at the given eigenvalue {}zaCannot evaluate the function because the derivative {} is not analytic at the given eigenvalue {})rr:r@ is_symbolrrrrmaxrrrrrro is_number is_complexr3solver)rr?reigenmax_mul derivativeddrrr)f_valrr}rriicoederid_irrpres r analytic_funczMatrixBase.analytic_funcsB8{HQK1~~& &{{3::1=> > ANN "/66q!<> > !! !3::1dCE E elln% w{# #Ab!B "Jq1u  # JJqM JJqM 1a ! A(C1E#JSz##E#J,A,A $$*F1eCj$9;;C1X #q& q Qw#(8,Rq,,Ag'C1HC$T*//15C}}S^^(,,2F:d3CS,IKK"%E#J"1X<t8a<1,()Ac1fI%&CF$!$QTA!6A$'F3q!d(+;$;#q& <AID#Ag$ 1HCC! D GGENjjmhhqkq A!S.C 4KC  7-s5 Kc|js td |j\}}|j}|Dcgc]}|j }}ddlm}||}|j|dj|jd}td|jDrt|t|St||S#t$r t dwxYwcc}w)aReturn the exponential of a square matrix. Examples ======== >>> from sympy import Symbol, Matrix >>> t = Symbol('t') >>> m = Matrix([[0, 1], [-1, 0]]) * t >>> m.exp() Matrix([ [ exp(I*t)/2 + exp(-I*t)/2, -I*exp(I*t)/2 + I*exp(-I*t)/2], [I*exp(I*t)/2 - I*exp(-I*t)/2, exp(I*t)/2 + exp(-I*t)/2]]) z0Exponentiation is valid only for square matricesz`Exponentiation is implemented only for matrices for which the Jordan normal form can be computedrrcNrc34K|]}|jywr)is_real)rrzs rrz!MatrixBase.exp..3s8u}}8r)r:r@rrr>rrrsrcrr?rrrr) rrrcellscellblocksrceJrets rr&zMatrixBase.exps~~&BD D t##%DAq%%'E >CCT$..0CC' 6]jjj.77T7R 8$++-8 84:bg& &4:c? " t%rt t tDs#C!C9!C6c|j}|d}|jrtdj|dt |i}t d|D]}| | z |z ||<ddlm}|j|||S)azHelper function to compute logarithm of a jordan block. Examples ======== >>> from sympy import Symbol, Matrix >>> l = Symbol('lamda') A trivial example of 1*1 Jordan block: >>> m = Matrix.jordan_block(1, l) >>> m._eval_matrix_log_jblock() Matrix([[log(lamda)]]) An example of 3*3 Jordan block: >>> m = Matrix.jordan_block(3, l) >>> m._eval_matrix_log_jblock() Matrix([ [log(lamda), 1/lamda, -1/(2*lamda**2)], [ 0, log(lamda), 1/lamda], [ 0, 0, log(lamda)]]) rzBCould not take logarithm or reciprocal for the given eigenvalue {}rr/r) rrr>rr'rrrr)rrUr:rrrs r_eval_matrix_log_jblockz"MatrixBase._eval_matrix_log_jblock8s0yy J 99 &q + +CF q$ )A"!}q(E!H ) (~~fT5122rc|js td |r||j\}}n|j\}}|j}|Dcgc]}|j }}ddlm}||}|r5|||z||jz} |j| } | S||z|jz} | S#t$r t dwxYwcc}w)aHReturn the logarithm of a square matrix. Parameters ========== simplify : function, bool The function to simplify the result with. Default is ``cancel``, which is effective to reduce the expression growing for taking reciprocals and inverses for symbolic matrices. Examples ======== >>> from sympy import S, Matrix Examples for positive-definite matrices: >>> m = Matrix([[1, 1], [0, 1]]) >>> m.log() Matrix([ [0, 1], [0, 0]]) >>> m = Matrix([[S(5)/4, S(3)/4], [S(3)/4, S(5)/4]]) >>> m.log() Matrix([ [ 0, log(2)], [log(2), 0]]) Examples for non positive-definite matrices: >>> m = Matrix([[S(3)/4, S(5)/4], [S(5)/4, S(3)/4]]) >>> m.log() Matrix([ [ I*pi/2, log(2) - I*pi/2], [log(2) - I*pi/2, I*pi/2]]) >>> m = Matrix( ... [[0, 0, 0, 1], ... [0, 0, 1, 0], ... [0, 1, 0, 0], ... [1, 0, 0, 0]]) >>> m.log() Matrix([ [ I*pi/2, 0, 0, -I*pi/2], [ 0, I*pi/2, -I*pi/2, 0], [ 0, -I*pi/2, I*pi/2, 0], [-I*pi/2, 0, 0, I*pi/2]]) z+Logarithm is valid only for square matricesz[Logarithm is implemented only for matrices for which the Jordan normal form can be computedrr) r:r@rrr>rrrsrcr?r) rr rrrrrrcrrs rr'zMatrixBase.log_sh~~&=? ? :~1131'')1%%'E  ( ( * ( 6] 1r6HQUUW$556C..%C b&1557"C # :%9: : : s?CC'C$c|sy|js tdtd|d}|j|}|jd||j zk(ryy)aChecks if a matrix is nilpotent. A matrix B is nilpotent if for some integer k, B**k is a zero matrix. Examples ======== >>> from sympy import Matrix >>> a = Matrix([[0, 0, 0], [1, 0, 0], [1, 1, 0]]) >>> a.is_nilpotent() True >>> a = Matrix([[1, 0, 1], [1, 0, 0], [1, 1, 0]]) >>> a.is_nilpotent() False Tz,Nilpotency is valid only for square matricesrc d|zS)Nrr)rs rrz)MatrixBase.is_nilpotent..s cAgr)modifyrF)r:r@r.rrr)rrrs r is_nilpotentzMatrixBase.is_nilpotents^$~~&>@ @ !#t4E F MM!  66!9TYY &rc|Dcgc]}t|tc}\}}|r6|jsdx}}nC|dj|jdd\}}nt |d|j}|dz}|r6|j sdx}}nC|dj|j dd\}}nt |d|j }|dz}||||fScc}w)zConverts a key with potentially mixed types of keys (integer and slice) into a tuple of ranges and raises an error if any index is out of ``self``'s range. See Also ======== key2ij rNrar/)rrvrrrr) rkeysrislicejslicerlorhiclochis r key2boundszMatrixBase.key2boundss9==1*Q.= 99 c7??4995bq9SQ+C'C 99 c7??4995bq9SQ+C'CCc!!#>sCct|r^t|dk(s tdt||jDcgc]#\}}t |t s t||n|%c}}St |t r|jt|ddStt|t||jScc}}w)zConverts key into canonical form, converting integers or indexable items into valid integers for ``self``'s range or returning slices unchanged. See Also ======== key2bounds raz"key must be a sequence of length 2N) r4rr ziprrrvrrrr)rrrrs rrwzMatrixBase.key2ijs s s8q= DEE #C 461(2!U';E!QKB6 6 U #;;s4y)"1- -%SY/; ; 6s(Cc|jdk7r|jdk7r td|j|r(|j |j|j}|S|j fd}|S)aReturn the normalized version of ``self``. Parameters ========== iszerofunc : Function, optional A function to determine whether ``self`` is a zero vector. The default ``_iszero`` tests to see if each element is exactly zero. Returns ======= Matrix Normalized vector form of ``self``. It has the same length as a unit vector. However, a zero vector will be returned for a vector with norm 0. Raises ====== ShapeError If the matrix is not in a vector form. See Also ======== norm r/z'A Matrix must be a vector to normalize.c|z Srr)rnorms rrz'MatrixBase.normalized..#s 1t8r)rrr?rrr<)rrQrBrs @r normalizedzMatrixBase.normalizedsn< 99>dii1nFG Gyy{ d **TYY 2C ..!34C rc t|jxsdg}tj|jvrdvrt t d|DSdk(rt d|DStjurt|Dcgc] }t|c}Stjurt|Dcgc] }t|c}S tt fd|Dtjz Sdk(rV|j!t}tt#|j$Dcgc]}t'|j)|c}Sdk(rt|j+Sd k(rt|j+StjurV|j!t}tt#|j,Dcgc]}t'|j/|c}S"t1t2r2j5d vr |j7j9d Std cc}wcc}w#ttf$r tdwxYwcc}wcc}w) aReturn the Norm of a Matrix or Vector. In the simplest case this is the geometric size of the vector Other norms can be specified by the ord parameter ===== ============================ ========================== ord norm for matrices norm for vectors ===== ============================ ========================== None Frobenius norm 2-norm 'fro' Frobenius norm - does not exist inf maximum row sum max(abs(x)) -inf -- min(abs(x)) 1 maximum column sum as below -1 -- as below 2 2-norm (largest sing. value) as below -2 smallest singular value as below other - does not exist sum(abs(x)**ord)**(1./ord) ===== ============================ ========================== Examples ======== >>> from sympy import Matrix, Symbol, trigsimp, cos, sin, oo >>> x = Symbol('x', real=True) >>> v = Matrix([cos(x), sin(x)]) >>> trigsimp( v.norm() ) 1 >>> v.norm(10) (sin(x)**10 + cos(x)**10)**(1/10) >>> A = Matrix([[1, 1], [1, 1]]) >>> A.norm(1) # maximum sum of absolute values of A is 2 2 >>> A.norm(2) # Spectral norm (max of |Ax|/|x| under 2-vector-norm) 2 >>> A.norm(-2) # Inverse spectral norm (smallest singular value) 0 >>> A.norm() # Frobenius Norm 2 >>> A.norm(oo) # Infinity Norm 2 >>> Matrix([1, -2]).norm(oo) 2 >>> Matrix([-1, 2]).norm(-oo) 1 See Also ======== normalized rraNc38K|]}t|dzywrrer s rrz"MatrixBase.norm..^s!.as2SV2sc3:K|]}t|zywrr)rrords rrz"MatrixBase.norm..ls =1Q3 =sz'Expected order to be Number, Symbol, oora)r?fro frobeniusvector)rzMatrix Norms under development)rrr#Onerr r InfinityrreNegativeInfinityrr-rr rr<rrr[rrrrrr@rNr8r)rrrJrr{s ` rrzMatrixBase.norm&sjDKKM")qc 55DJJ iC!>2T233 "T2SV233***T2SV233 L3 = => LL axNN3'E!&&MBqSq]BCCD00233D00233 "NN3'E!&&MBqSq]BCC+C,/"158YY[364xxz1--**JKKK33 (3 L !JKK LCCs$I8I+I 1!I+!I0 I(cZg}t|jD]w}g}t|jD]8}|||fdk(r|jd|jt |:|jddj |zyt dj |y)aShows location of non-zero entries for fast shape lookup. Examples ======== >>> from sympy import Matrix, eye >>> m = Matrix(2, 3, lambda i, j: i*3+j) >>> m Matrix([ [0, 1, 2], [3, 4, 5]]) >>> m.print_nonzero() [ XX] [XXX] >>> m = eye(4) >>> m.print_nonzero("x") [x ] [ x ] [ x ] [ x] r z[%s] N)rrrrr@joinprint)rsymbrrliners r print_nonzerozMatrixBase.print_nonzeros. tyy! -AD499% +1:?KK$KKD *  + HHVbggdm+ , - diilrcN||j||j|z zS)a^Return the projection of ``self`` onto the line containing ``v``. Examples ======== >>> from sympy import Matrix, S, sqrt >>> V = Matrix([sqrt(3)/2, S.Half]) >>> x = Matrix([[1, 0]]) >>> V.project(x) Matrix([[sqrt(3)/2, 0]]) >>> V.project(-x) Matrix([[sqrt(3)/2, 0]]) )r)rrs rprojectzMatrixBase.projects$DHHQK!%%(*++rc^tj|jvryg}dg|jz}t |j D]r} |j gt |jD]G} |j|| | f} |dj | tt| || || <Itddddddd|}t|D]J\} } t| D]\} } t| ||| | | <||j| z|z|| <L|j|S)a String form of Matrix as a table. ``printer`` is the printer to use for on the elements (generally something like StrPrinter()) ``rowstart`` is the string used to start each row (by default '['). ``rowend`` is the string used to end each row (by default ']'). ``rowsep`` is the string used to separate rows (by default a newline). ``colsep`` is the string used to separate columns (by default ', '). ``align`` defines how the elements are aligned. Must be one of 'left', 'right', or 'center'. You can also use '<', '>', and '^' to mean the same thing, respectively. This is used by the string printer for Matrix. Examples ======== >>> from sympy import Matrix, StrPrinter >>> M = Matrix([[1, 2], [-33, 4]]) >>> printer = StrPrinter() >>> M.table(printer) '[ 1, 2]\n[-33, 4]' >>> print(M.table(printer)) [ 1, 2] [-33, 4] >>> print(M.table(printer, rowsep=',\n')) [ 1, 2], [-33, 4] >>> print('[%s]' % M.table(printer, rowsep=',\n')) [[ 1, 2], [-33, 4]] >>> print(M.table(printer, colsep=' ')) [ 1 2] [-33 4] >>> print(M.table(printer, align='center')) [ 1 , 2] [-33, 4] >>> print(M.table(printer, rowstart='{', rowend='}')) { 1, 2} {-33, 4} z[]rrljustrjustcenter)rrr<>^) r#rrrrrr_printrrrr=r)rrErowstartrowendrCcolsepalignresmaxlenrrrrelems rrDzMatrixBase.tablesBd 66TZZ tyytyy! 3A JJrN499% 3NN41:.Bq!Aq 2q  3 3    n :FAs$S> 94-u-fQi8A 9 C 0069CF :{{3rct|||Sr})r~r~s rrank_decompositionzMatrixBase.rank_decomposition s"4J!# #rctdNz;This function is implemented in DenseMatrix or SparseMatrixrrrs rcholeskyzMatrixBase.cholesky!"_``rctdrrrs rLDLdecompositionzMatrixBase.LDLdecompositionrrc t||||SN)rQr rankcheck)rrrQrrs rLUdecompositionzMatrixBase.LUdecompositionsh#% %rc t||||Sr)rr s rLUdecomposition_Simplez!MatrixBase.LUdecomposition_Simples&t !Y8 8rct|Sr)rrs rLUdecompositionFFzMatrixBase.LUdecompositionFFs !$''rct|Sr)rrs rsingular_value_decompositionz'MatrixBase.singular_value_decomposition!s ,T22rct|Sr)rrs rQRdecompositionzMatrixBase.QRdecomposition$rrct|Sr)rrs rupper_hessenberg_decompositionz)MatrixBase.upper_hessenberg_decomposition's .t44rct||Sr)rWrrs rdiagonal_solvezMatrixBase.diagonal_solve*tS))rctdrrrs rlower_triangular_solvez!MatrixBase.lower_triangular_solve-rrctdrrrs rupper_triangular_solvez!MatrixBase.upper_triangular_solve0rrct||Sr)rZrs rcholesky_solvezMatrixBase.cholesky_solve3rrct||Sr)r[rs rLDLsolvezMatrixBase.LDLsolve6ss##rct|||SrP)r\)rrrQs rLUsolvezMatrixBase.LUsolve9scj99rct||Sr)r]rs rQRsolvezMatrixBase.QRsolve<sa  rct|||S)N)freevar)r^)rr r&s rgauss_jordan_solvezMatrixBase.gauss_jordan_solve?s"4G<>rct|||Src)rarrrCs rrzMatrixBase.solveHsdC//rct|||Src)rbr/s rsolve_least_squareszMatrixBase.solve_least_squaresKs#D#f==rct||Src)rcres rpinvzMatrixBase.pinvNsT&))rct||SrP)rdrSs r inverse_ADJzMatrixBase.inverse_ADJQ44rct||SrP)rkrSs r inverse_BLOCKzMatrixBase.inverse_BLOCKTs$:66rct||SrP)rerSs r inverse_GEzMatrixBase.inverse_GEWt 33rct||SrP)rfrSs r inverse_LUzMatrixBase.inverse_LUZr;rct||SrP)rgrSs r inverse_CHzMatrixBase.inverse_CH]r;rct||SrP)rhrSs r inverse_LDLzMatrixBase.inverse_LDL`r6rct||SrP)rirSs r inverse_QRzMatrixBase.inverse_QRcr;rc t||||S)N)rCrQtry_block_diag)rj)rrCrQrEs rr?zMatrixBase.invfsDJ-/ /rct|Sr)rrs rconnected_componentszMatrixBase.connected_componentsjs $T**rct|Sr)rrs r"connected_components_decompositionz-MatrixBase.connected_components_decompositionms 2488rct|Sr)rrs rstrongly_connected_componentsz(MatrixBase.strongly_connected_componentsps -d33rct||S)N)rN)r)rrNs r+strongly_connected_components_decompositionz6MatrixBase.strongly_connected_components_decompositionss;DNNr)r)TTr)rUrr)NN)returnr9)T)NdFFNF)TNTTTTTT)rr)r)FTNr)r)bareissN)r)rNNNN)F)FFF)rNr=)r)[r'rr&r)laplace)GJ)CH)RD(__name__ __module__ __qualname____doc__ _op_priority__array_priority__rk_class_priority staticmethodrrr#rrrrHr__annotations__r1 classmethodrrrpropertyrrrrrrrrrrrrrrrrrrrrrr+r!r#rrrrr.r0r6r8r=r?rDrKrWr\r^rircrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr r"r$r&r)r:r,r;r0r2r4rrrr=rDrFrLrTrXr\r`rr<rgrJrlrvrzrrrrr rrr rorr;rdrrrrrrrrrrrrrrrrr r rr7rrr"r%r rr.r0r4r3rrr&rHrMrJrCrTrVrBrXrZr\r`rfr rrlrnrprrrtrvrDrErLrMrNrOrPrKrFrGrHrIrJrQrRryr{rrrrTrSrUrVrrrrrrrrrrrrrrlrmrnrorrrrrrrrrrrrrrrprqrtrurvrwrxryrzr{r|r}rrrsrrrrrrrrrrrrrrrrrr r%r'r*r)objectr2r4r9rArFrPrUrur}rrrrGrrrrfrrrrr&rrr'rrrwrrrrrDrrrr r rrrrrrrrr r"r$r'r*r-rr1r3r5r8r:r=r?rArCr?rGrIrKrMr _sage_r~rrrrrrrrrWrXrYrZr[r\r]r^r_r`rarbrcrdrerfrgrhrirkrjrrrrrrrrrcs5LIOG$H 66D %%CIt I IIEE EE&&": C 04*: E 0;.. . '''1R*@,<6|,4**&46'(1T*>0)d( "33"#>2 40)d***++66 ++"++ HH   %dDK:K:Z++._@g_@_@B,,(--.'+'+T%(%(T4(- ;JA H@F QJJNNGHBE(2 ) ))2E6N)(V/;/;b/;/;bCCB(( 008*%*%X&&. (>1@008)%)%V++<#((&'&A$87669H$'.) &89? JN;?&2G1R L L@( GD+$Z >A*"$!&F    +:"> =$6L$6LM@ 7R7  -4MMT :&'$>*)+)=)#*#3:&$'$<#"J84):&' \|9%#&#<($)$9%%&% "D9%&:&',E9$'.G".",?745@1,,B+I+I"+G+O+O (+7+?+?+9+A+A(1(9(9N+7+?+?+2??L+/<<+4+<+>EM+;+C+CO&-5)!!&E2(&d: )00L&..J ==DL ==DL5&n666666M<M<5"'7J2 4)00K&..I%--H*22M' 6MV040I%1<++//++//$$K/&*4););I)4)<))F)F )B)J)J$)>)F)F )B)J)J$)7)?)?M)5)=)=K)9)A)AO)9)A)AO)7)?)?M)B)J)J$#'85F68@t8.$)?=P",'&/P3"%(>&/*=<$$P(%4/ %$B1 D''R:: a%a%FDL;0<""4H5nM^("("TdL&P%3P\~!#F%3N"Pd:":<(%,%NcLJ D, ?C!(K Z-4e#aa*14% 18$8 (3&5*aa*$'.:!=G?0>*&-5(/7%,4%,4%,4&-5%,4'%/+94O\\F%8%@%@%.%6%6H%6%>%>%5%=%=O%<%D%D"%7%?%?+H+P+P (%5%=%=O-L-T-T"*%4%<%>> from sympy import Matrix, ImmutableMatrix >>> from sympy.matrices.matrixbase import classof >>> M = Matrix([[1, 2], [3, 4]]) # a Mutable Matrix >>> IM = ImmutableMatrix([[1, 2], [3, 4]]) >>> classof(M, IM) r]NrzIncompatible classes r&)r=r]rnumpyrndarray ImportErrorr )r r  priority_A priority_Bros rrrs -t4J-t4J J ++  q00 0;; ;;  a ';;  a ';;  Q[[!++N OO    sC C  C ct||\}}|dk(rBt||}||jk7r t||}||jk7r t||}|||fS)zDUnify self and other into a single matrix type, or check for scalar.r)rrrrf)rrrdres rrrsbtU+HE1KdE" $.. "3-D %// !#C/E >rct|ts&t|dd}||}ntd|d|#|dkr||z }|dk\r||kstd|dt|S)z>Return integer after making positive and validating against n. __index__NzInvalid index a[r'rzIndex out of range: a[)rrr=r)rrjindexs rrrsn a K.  Aa9: :} q5 FAQ1q5A?@ @ q6Mrc"eZdZdZdZdZdZy)rqa5A vector whose components are deferred (e.g. for use with lambdify). Examples ======== >>> from sympy import DeferredVector, lambdify >>> X = DeferredVector( 'X' ) >>> X X >>> expr = (X[0] + 2, X[2] + 3) >>> func = lambdify( X, expr) >>> func( [1, 2, 3] ) (3, 6) ch|dk(rd}|dkr tdd|j|fz}t|S)Nrz!DeferredVector index out of rangez%s[%d])rnamer)rrcomponent_names rrzDeferredVector.__getitem__(s> 7A q5@A A!TYYN2n%%rct|Srrrs rrAzDeferredVector.__str__0rarc d|jzS)NzDeferredVector('%s'))rzrs r__repr__zDeferredVector.__repr__3s% 11rN)rWrXrYrZrrAr~rrrrqrqs &2rrqr) __future__r collectionsrcollections.abcrinspectr functoolsrsympy.assumptions.refiner sympy.corer r sympy.core.basicr r sympy.core.kindrsympy.core.numbersrsympy.core.modrsympy.core.symbolrrsympy.core.sympifyrrsympy.core.functionr sympy.polysr$sympy.functions.elementary.complexesrrrsympy.printingr(sympy.functions.elementary.miscellaneousrrr (sympy.functions.special.tensor_functionsr!r"sympy.core.singletonr#sympy.printing.defaultsr$sympy.printing.strr%&sympy.functions.elementary.exponentialr&r'(sympy.functions.combinatorial.factorialsr(r)mpmathror*sympy.utilities.iterablesr+sympy.core.exprr,sympy.core.powerr-r. utilitiesr0r1r sympy.polys.polytoolsr2r3r4sympy.utilities.miscr5r6sympy.core.decoratorsr7sympy.core.logicr8r9sympy.tensor.arrayr:r;r<r*r= exceptionsr>r?r@rArBrC determinantrDrErFrGrHrIrJrKrLrMrNrOrPrQrR reductionsrSrTrUrVsolversrWrXrYrZr[r\r]r^r_r`rarbinversercrdrerfrgrhrirjrk subspacesrlrmrnrorrprqrrrsrtrurvrwrxryrzr{r|r}decompositionsr~rrrrrrrrgraphrrrr__doctest_requires__rrfrhrjrrrrrqrrrrsk"#$+(()&+0$<<CCO"-);H$- 3E&:371(12: A@>>>> KJ6666VVV RR ,/;^ |P=|P=~a 8=6"PJ   2V[2r