Make the diagonal of a matrix 0. Python

2

Good morning everyone,

I would like to be able to make the diagonal of a matrix equal to 0 with some type of command, does anyone know how? Is there any numpy that can do it? for example SO:

     [,0] [,1] [,2] [,3] [,4]
[0,]    0    0    1    1    0
[1,]    1    0    1    1    0
[2,]    0    1    0    1    1
[3,]    1    1    1    0    1
[4,]    0    0    0    0    0

The diagonal is composed of 0

Thank you very much.

    
asked by Fran Ahedo Guerrero 03.08.2017 в 10:12
source

1 answer

3

If you mean that you want the diagonal to have pure 0's if it can be done with numpy, look at this example:

a = np.zeros((3, 3),int) #Inicializo una matriz
np.fill_diagonal(a,5) # Relleno la diagonal con un valor especifico

In short, it would be enough to add

np.fill_diagonal(matriz,0)
    
answered by 03.08.2017 / 10:24
source