Alexander Vocaet
Alexander Vocaet

Reputation: 188

MinMax scale Array with Maximum und Minimum of whole Array

I got this np.array which needs to be scaled with the maximum of the whole array and the minimum of the whole array, in order to sustain relations between Data.

Is there a library able to do so?

Upvotes: 0

Views: 401

Answers (1)

ryuzakyl
ryuzakyl

Reputation: 549

I might have not correctly understood your question, but to me it can be interpreted as an interval interpolation problem.

You can use the linear interpolation function from numpy (np.interp):

# re-scale all array values in [-1, 1] interval
arr_min = arr.min()
arr_max = arr.max()
arr_scaled = np.interp(arr, (arr_min, arr_max), (-1, +1))

# in one line
arr_scaled = np.interp(arr, (arr.min(), arr.max()), (-1, +1))

This also works on numpy arrays where arr.ndim > 1.

Hope it helps.

Upvotes: 1

Related Questions