kevbuntu - 9 months ago 47

Python Question

Trying to normalize the input data which a matrix of images in to a mean of 0 and a range of -0.5 and 0.5 in python

`def normalise(image):`

return 0.1 + (((image_data-0)*(0.9-0.1))/(255 - 0))

Was trying to use min-max scaling, but wrong answer I get close to 0.1 for min and max

Answer Source

You want scaling. Here is example:

```
from sklearn import preprocessing
import numpy as np
data = np.array([70, -5, 5, 3, 2, 1])
scale = preprocessing.minmax_scale(data, feature_range=(-0.5, 0.5))
print scale
```

out:

```
[ 0.5 -0.5 -0.36666667 -0.39333333 -0.40666667 -0.42 ]
```