From: Todd M. <jm...@st...> - 2002-07-25 17:14:17
|
Aureli Soria Frisch wrote: > Hi all, > > Has someone implemented a function for arrays that behaves like the > index(*) method for lists (it should then consider something like a > tolerance parameter). > > I suppose it could be maybe done with array.tolist() and list.index(), > but have someone implemented something more elegant/array-based? > > Thanks in advance > > Aureli > > PD: (*) index receive a value as an argument and retunrs the index of > the list member equal to this value... I think the basics of what you're looking for are something like: def index(a, b, eps): return nonzero(abs(a-b) < eps) which should return all indices at which the absolute value of the difference between elements of a and b differ by less than eps. e.g.: >>> import Numeric >>> index(Numeric.arange(10,20), 15, 1e-5) array([5]) Todd -- Todd Miller jm...@st... STSCI / SSG (410) 338 4576 |