The rows of this matrix are not linearly independent, as the first two rows can be added (or XORed) to produce the third:
matrix = [
[ 1, 0, 0, 1 ],
[ 0, 0, 1, 0 ],
[ 1, 0, 1, 1 ],
[ 1, 1, 0, 1 ]
]
One could do brute-force reduction of the rows, with deeply nested for loops and if conditions and testing for an all zero row, but the resulting code doesn't feel like python.
Without using numpy or other library, what is a pythonic way of testing for independent rows (on much larger matrices)?
My guess is that you want something like this:
If so, then calling algorithmically terrible code like this "Pythonic" and row reduction "brute force" suggests that your aesthetic principles are a problem. Because row reduction is absolutely the right approach.
For comparison here is the row reduction solution.
Algorithmically the combinations code for an
n x m
matrix scales likeO(m * n * 2^n)
. Row reduction scales likeO(m * n^2)
. Which is much better.