Return True if array `x` is a binary array with a single 1
(x)
| 41 | |
| 42 | |
| 43 | def is_one_hot(x): |
| 44 | """Return True if array `x` is a binary array with a single 1""" |
| 45 | msg = "Matrix should be one-hot binary" |
| 46 | assert np.array_equal(x, x.astype(bool)), msg |
| 47 | assert np.allclose(np.sum(x, axis=1), np.ones(x.shape[0])), msg |
| 48 | return True |
| 49 | |
| 50 | |
| 51 | def is_binary(x): |
nothing calls this directly
no outgoing calls
no test coverage detected