I have to create a program that eliminates rows and columns
the program has to analyze all the elements of a column and if all are 0, that column and its corresponding row is deleted
for example if all the elements in column 6 are 0, column 6 and row 6 are deleted
first the program asks the user for the dimensions of the matrix and then its values
import numpy
from numpy import delete
m = int(input("Dimension de la matriz:"))
matriz_v = numpy.zeros((m,m))
print ("Introducir los elementos de la matriz")
for f in range(0,m):
for c in range(0,m):
matriz_v[(f),(c)] = (input("Elemento ["+str(f+1)+","+str(c+1)+"] "))
print (matriz_v)
For example, all the elements in column 4,5,6 are 0
and I want this where the rows and columns 4,5,6 are deleted
I am trying with this idea, add all the elements of the column and if the sum is equal to 0, this is eliminated, (since in my case of study the only way that the sum of all the terms of a column is 0, is if all the terms are 0)
for x in range(0,m):
suma_columna = 0
for y in range(0,m):
suma_columna = suma_columna + matriz_v[y][x]
if (suma_columna == 0):
matriz_v_c = delete(matriz_v, [x], axis=1)
matriz_v_c_f = delete(matriz_v_c, [x], axis=0)
but I only delete 1 row and 1 column and not all that I need
thanks