def test_binarizer(): from sklearn.preprocessing import Binarizer arr = np.array([0, 1, 2, 3, 4]) print Binarizer(threshold=2).fit_transform(arr) # [[0 0 0 1 1]]