To make a matrix in SymPy, use the ** Matrix** object. A matrix is constructed by providing a list of row vectors that make up the matrix. For example, to construct the matrix

use

To make it easy to make column vectors, a list of elements is considered to be a column vector.

Matrices are manipulated just like any other object in SymPy or Python.

One important thing to note about SymPy matrices is that, unlike every other object in SymPy, they are mutable. This means that they can be modified in place, as we will see below. The downside to this is that ** Matrix** cannot be used in places that require immutability, such as inside other SymPy expressions or as keys to dictionaries. If you need an immutable version of

**, use**

`Matrix`

**.**

`ImmutableMatrix`

**Operazioni di base
**

`shape`

Here are some basic operations on

**. To get the shape of a matrix use**

`Matrix`

`shape`

**accedere a righe e colonne**

To get an individual row or column of a matrix, use ** row** or

**. For example,**

`col`

**will get the first row.**

`M.row(0)`

**will get the last column.**

`M.col(-1)`

**cancellare e inserire righe e colonne**

To delete a row or column, use ** row_del** or

**. These operations will modify the Matrix**

`col_del`

*.*

**in place**To insert rows or columns, use ** row_insert** or

**. These operations**

`col_insert`

*operate in place.*

**do not**Unless explicitly stated, the methods mentioned below do not operate in place. In general, a method that does not operate in place will return a new ** Matrix** and a method that does operate in place will return

**.**

`None`

**Metodi base**

As noted above, simple operations like addition and multiplication are done just by using ** +**,

**, and**

`*`

**. To find the inverse of a matrix, just raise it to the**

`**`

**power.**

`-1`

To take the transpose of a ** Matrix**, use

**.**

`T`

**Costruttori**

Several constructors exist for creating common matrices. To create an identity matrix, use ** eye**.

**will create an**

`eye(n)`

**identity matrix.**

`n×n`

To create a matrix of all zeros, use ** zeros**.

**creates an**

`zeros(n, m)`

**matrix of 0s.**

`n×m`

Similarly, ** ones** creates a matrix of ones.

To create diagonal matrices, use ** diag**. The arguments to

**can be either numbers or matrices. A number is interpreted as a**

`diag`

**matrix. The matrices are stacked diagonally. The remaining elements are filled with 0s.**

`1×1`