Did I find the right examples for you? yes no

# sympy.matrices.diag

All Samples(52)  |  Call(42)  |  Derive(0)  |  Import(10)

```from sympy.matrices.matrices import (ShapeError, MatrixError,
NonSquareMatrixError, DeferredVector)
from sympy.matrices import (
GramSchmidt, ImmutableMatrix, ImmutableSparseMatrix, Matrix,
SparseMatrix, casoratian, diag, eye, hessian,
```
```def test_diag():
a = Matrix([[1, 2], [2, 3]])
b = Matrix([[3, x], [y, 3]])
c = Matrix([[3, x, 3], [y, 3, z], [x, y, z]])
assert diag(a, b, b) == Matrix([
```
```        [0, 0, 0, 0, y, 3],
])
assert diag(a, b, c) == Matrix([
[1, 2, 0, 0, 0, 0, 0],
[2, 3, 0, 0, 0, 0, 0],
```
```        [0, 0, 0, 0, x, y, z],
])
assert diag(a, c, b) == Matrix([
[1, 2, 0, 0, 0, 0, 0],
[2, 3, 0, 0, 0, 0, 0],
```
```    b = Matrix([[1, 2], [3, 4]])
c = Matrix([[5, 6]])
assert diag(a, 7, b, c) == Matrix([
[x, 0, 0, 0, 0, 0],
[y, 0, 0, 0, 0, 0],
```

```from sympy.matrices.matrices import (ShapeError, MatrixError,
NonSquareMatrixError, DeferredVector)
from sympy.matrices import (
GramSchmidt, ImmutableMatrix, ImmutableSparseMatrix, Matrix,
SparseMatrix, casoratian, diag, eye, hessian,
```
```def test_diag():
a = Matrix([[1, 2], [2, 3]])
b = Matrix([[3, x], [y, 3]])
c = Matrix([[3, x, 3], [y, 3, z], [x, y, z]])
assert diag(a, b, b) == Matrix([
```
```        [0, 0, 0, 0, y, 3],
])
assert diag(a, b, c) == Matrix([
[1, 2, 0, 0, 0, 0, 0],
[2, 3, 0, 0, 0, 0, 0],
```
```        [0, 0, 0, 0, x, y, z],
])
assert diag(a, c, b) == Matrix([
[1, 2, 0, 0, 0, 0, 0],
[2, 3, 0, 0, 0, 0, 0],
```
```    b = Matrix([[1, 2], [3, 4]])
c = Matrix([[5, 6]])
assert diag(a, 7, b, c) == Matrix([
[x, 0, 0, 0, 0, 0],
[y, 0, 0, 0, 0, 0],
```

```
blocks = list(map(_jblock_exponential, cells))
from sympy.matrices import diag
eJ = diag(* blocks)
# n = self.rows
```
```
"""
from sympy.matrices import diag

if not self.is_square:
```
```                        vec = vec / vec.norm()
P = P.col_insert(P.cols, vec)
D = diag(*diagvals)
self._diagonalize_clear_subproducts()
return (P, D)
```
```        """
P, Jcells = self.jordan_cells()
from sympy.matrices import diag
J = diag(*Jcells)
return P, type(self)(J)
```

```
blocks = list(map(_jblock_exponential, cells))
from sympy.matrices import diag
eJ = diag(* blocks)
# n = self.rows
```
```
"""
from sympy.matrices import diag

if not self.is_square:
```
```                        vec = vec / vec.norm()
P = P.col_insert(P.cols, vec)
D = diag(*diagvals)
self._diagonalize_clear_subproducts()
return (P, D)
```
```        """
P, Jcells = self.jordan_cells()
from sympy.matrices import diag
J = diag(*Jcells)
return P, type(self)(J)
```

```        inverse_ADJ
"""
from sympy.matrices import diag

method = kwargs.get('method', 'GE')
```
```            for block in blocks:
r.append(block.inv(method=method, iszerofunc=iszerofunc))
return diag(*r)

M = self.as_mutable()
```

```        inverse_ADJ
"""
from sympy.matrices import diag

method = kwargs.get('method', 'GE')
```
```            for block in blocks:
r.append(block.inv(method=method, iszerofunc=iszerofunc))
return diag(*r)

M = self.as_mutable()
```