I am given a list of square matrices (with non numeric entries but abstract symbols which are assumed to take real values) and I want to write a function that returns True if the following condition is satisfied:
- All rows and columns of each matrix have at most one nonzero element.
In other words, a row or column can either have all elements zero, or all but one. Otherwise, the function should return False.
I could of course write a triple loop that goes through each matrix in the list, then each row and column, and counts non-zero elements, but I am wondering what would be the most clever and efficient way to do it.
Note that even if only one matrix in that list has a row or column with more than one non-zero elements, then there would be no need to check for the rest.