Ejemplo 1: Python crea una matriz con una en diagonal
# Create a matrix in python and fill
import numpy as np
a = np.zeros((3, 3), int) # Create matrix with only 0
np.fill_diagonal(a, 1) # fill diagonal with 1
print(a)
Ejemplo 2: numpy obtiene matriz diagonal de matriz
np.diag(np.diag(x))
Ejemplo 3: matriz diagonal de bloques numpy de Python
>>> from scipy.linalg import block_diag
>>> A = [[1, 0],
... [0, 1]]
>>> B = [[3, 4, 5],
... [6, 7, 8]]
>>> C = [[7]]
>>> P = np.zeros((2, 0), dtype="int32")
>>> block_diag(A, B, C)
array([[1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 3, 4, 5, 0],
[0, 0, 6, 7, 8, 0],
[0, 0, 0, 0, 0, 7]])
>>> block_diag(A, P, B, C)
array([[1, 0, 0, 0, 0, 0],
[0, 1, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0],
[0, 0, 3, 4, 5, 0],
[0, 0, 6, 7, 8, 0],
[0, 0, 0, 0, 0, 7]])
>>> block_diag(1.0, [2, 3], [[4, 5], [6, 7]])
array([[ 1., 0., 0., 0., 0.],
[ 0., 2., 3., 0., 0.],
[ 0., 0., 0., 4., 5.],
[ 0., 0., 0., 6., 7.]])
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)