[SciPy-User] find intervall in array
Massimo Di Stefano
massimodisasha at yahoo.it
Tue Jan 26 05:15:10 EST 2010
Hi All,
i have a 2xN array where :
- first column = integer values sorted from min to max
- second column = float values (range 0 - 1)
an example array can look like :
from numpy import zeros, array
import random
a = zeros((100,2),float)
for i in range(100):
a[i,0] = random.randrange(1000,2000,10)
a[i,1] = random.random()
the first column represent "Z" (elevation values)
the second column represent percentage 0 = 0% , 1 = 100% (pixel % coverage in a map at given Z)
i need to detect the Z value correspond to a precise percentage (25%, 50%, 75%)
he Z value i need to find is deducted from a formula like :
z = z1 + ((z2 - z1) / (f2 - f1)) * (f - f1)
where :
f = precise percentage (know value) -> (0.25, 0.50, 0.75) [this value can be not present in the a[i,1] array]
f1, f2 = are the a[i,1] values near the " f " value where [ f1 <= f <= f2 ]
z1, z2 = Z value correspond to the f1, f2
as example :
array a =
z f
1234 0.03
1345 0.58
1456 0.24
1457 0.63
1458 0.41
1459 0.78
1365 0.7
1468 0.56
1545 0.54
if
f = 0.5 :
z = 1545 + ((1468 - 1545) / (0.56 - 0.54)) * (0.5 - 0.54)
any suggestion on how can i find "f1 , f2" ?
thanks!!!
Massimo.
More information about the SciPy-User
mailing list