I have two sampled vectors, there one vector maximum value is 0.8 and the minimum value is -0.8. 2nd vector minimum value is 0.2 and maximum value is 0.3. There 1st and 2nd vector, I want to re map all the values in sampled vector between -1 to 1. How do I do that. Im looking for method which applying outlined two vectors. Thank you in advance.
Sampled vector 1.
[ -0.8, 0.7 , -0.23, 0.56, 0.456, -0.344, -0.75, 0.8]
Sampled vector 2.
[ 0.2, 0.23, 0.21, 0.29, 0.26, 0.25, 0.3]
CodePudding user response:
General formula to map xmin..xmax
range onto new_min..new_max
one:
X' = new_min (new_max - new_min)*(X - xmin)/(xmax-xmin)
for destination range -1..1:
X' = -1 2 * (X - xmin) / (xmax-xmin)
for source range 0.2..0.3:
X' = -1 20 * (X - 0.2) = -5 20 * X
CodePudding user response:
You are trying to normalize between [-1, 1]
Obtain the ratio:
norm_ratio = 1/.8
and multiply every element in your vector to get the desired result