How to "squish" a range of numbers to the same spread between 0 and 1 So I have a range of numbers that I need to "squish" into values between 0 and 1 - where lowest value is zero and the highest is 1. I need preserve the ratio.
For instance. If I had these example arrays (all the same ratio between each other):
0, 2000, 8000, 10000
0, 4000, 16000, 20000
0, 200000, 800000, 1000000
I'm hoping to get back a result something like this for each of those individual arrays:
0, 0.2, 0.8, 1
Notice that the ratio between the numbers is preserved.
Is there a built in function somewhere (in numpy?) that does this for me?
 A: You're asking for a function $f$, defined on some closed interval $\left[m, M\right]$, with values is $\left[0, 1\right]$, with the property that:
$$\frac{f(x)}{f(y)} = \frac{x}{y}$$
for all $x < y$ in said interval.
From this specification, we can derive a property the function must have. Fix $y$ to any non-zero value for which $f(y) \neq 0$, and let $x$ stay variable:
$$\frac{f(x)}{f(y)} = \frac{x}{y} \Rightarrow f(x) = \frac{f(y)}{y} x = \text{constant} \times x$$
So any such function must be of the form $f(x) = c x$. Bringing in the requirement that $f(m) = 0$:
$$
0 = f(m) = c m
$$
So either $c$ or $m$ must be zero. We can't have $c = 0$, since then everything collapses, so it must be the case that $m = 0$.
Therefore, such a function exists only when $m = 0$. In this case, such a function is easy to construct: $f(x) = \frac{x}{M}$.
A: Your specifications are not entirely clear to me.
Maybe starting with x and ending with y or z will
do what you want. [Arithmetic and plots using R.]
set.seed(1234)
x = rexp(20, .001)
min(x); max(x)
[1] 6.581957
[1] 3052.458

y = x/max(x)
min(y); max(y)
[1] 0.002156281
[1] 1

z = (x - min(x))/(max(x)- min(x))
min(z); max(z)
[1] 0
[1] 1

par(mfrow=c(1,3))
 hist(x, prob=T, col="skyblue2"); rug(x)
 hist(y, prob=T, col="skyblue2"); rug(y)
 hist(z, prob=T, col="skyblue2"); rug(z)
par(mfrow=c(1,1))


