I use the following way to scale an n-dimensional array between 0 and 1:
x_scaled = (x-np.amin(x))/(np.amax(x)-np.amin(x))
But it's very slow for large datasets. I have thousands of relatively large arrays which I need to process. Is there a faster method to this in python?
Edit: My arrays are in shape (24,24,24,9). For MinMax scaler in scikit, the input array has to have a certain shape which mine doesn't so I can't use it. In the documentation it says:
Parameters:
X : array-like, shape [n_samples, n_features]
It's risky to use ptp, i.e. max - min, as it can in theory be 0, leading to an exception. It's safer to use minmax_scale as it doesn't have this issue. First, pip install scikit-learn.
from sklearn.preprocessing import minmax_scale
minmax_scale(array)
If using an sklearn Pipeline, use MinMaxScaler instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With