From: Perry G. <pe...@st...> - 2005-05-17 15:19:46
|
It's simpler in numarray: i,j =3D where(z<0.5) For numeric it's more work: ind =3D where(z.flat < 0.5) i =3D ind//z.shape[1] j =3D ind % z.shape[1] One could turn this into a function for Numeric (to handle all=20 dimensionalities, etc) On May 17, 2005, at 10:04 AM, Dimitri D'Or wrote: > Hello, > > =A0 > > Here under a question that has probably already been asked: > > =A0 > > I would like to apply the find() function on a bidimensional array and=20= > receive as output the bidimensional indices for the elements matching=20= > the condition. This is easy in Matlab but doesn't seem to be possible=20= > with Python. > > =A0 > > Here is a short example (in Matlab code) of what I would like to have: > > =A0 > > >> z=3Drand(3,3) > > =A0 > > z =3D > > =A0 > > =A0=A0=A0 0.9501=A0=A0=A0 0.4860=A0=A0=A0 0.4565 > > =A0=A0=A0 0.2311=A0=A0=A0 0.8913=A0=A0=A0 0.0185 > > =A0=A0=A0 0.6068=A0=A0=A0 0.7621=A0=A0=A0 0.8214 > > =A0 > > >> [i,j]=3Dfind(z<0.5) > > =A0 > > i =3D > > =A0 > > =A0=A0=A0=A0 2 > > =A0=A0=A0=A0 1 > > =A0=A0=A0=A0 1 > > =A0=A0=A0=A0 2 > > =A0 > > =A0 > > j =3D > > =A0 > > =A0=A0=A0=A0 1 > > =A0=A0=A0=A0 2 > > =A0=A0=A0=A0 3 > > =A0=A0=A0=A0 3 > > =A0 > > A solution for me? > > =A0 > > Thank you, > > =A0 > > Dimitri D'Or > > =A0 |