MCPcopy Create free account
hub / github.com/ddbourgin/numpy-ml / is_one_hot

Function is_one_hot

numpy_ml/utils/testing.py:43–48  ·  view source on GitHub ↗

Return True if array `x` is a binary array with a single 1

(x)

Source from the content-addressed store, hash-verified

41
42
43def 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
51def is_binary(x):

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected