How do I convert a numpy matrix into a boolean matrix?
Simply use equality check:
Suppose a is your numpy matrix, use b = (a == 0) or b = (a != 0) to get the boolean value matrix.
In some case, since the value maybe sufficiently small but non-zero, you may use abs(a) < TH, where TH is the numerical threshold you set.
I have a n x n matrix in numpy which has 0 and non-0 values. Is there a way to easily convert it to a boolean matrix?
Thanks.