from sklearn import preprocessing
import numpy as np
data = np.array([[2.2, 5.9, -1.8], [5.4, -3.2, -5.1], [-1.9, 4.2, 3.2]])
bindata = preprocessing.Binarizer(threshold=1.5).transform(data)
print('Binarized data:\n\n', bindata)
Binarized data: [[ 1. 1. 0.] [ 1. 0. 0.] [ 0. 1. 1.]]
print('Mean (before)= ', data.mean(axis=0))
print('Standard Deviation (before)= ', data.std(axis=0))
Mean (before)= [ 1.9 2.3 -1.23333333] Standard Deviation (before)= [ 2.98775278 3.95052739 3.41207008]
scaled_data = preprocessing.scale(data)
print('Mean (after)= ', scaled_data.mean(axis=0))
print('Standard Deviation (after)= ', scaled_data.std(axis=0))
Mean (after)= [ 0.00000000e+00 0.00000000e+00 7.40148683e-17] Standard Deviation (after)= [ 1. 1. 1.]