From: Todd M. <jm...@st...> - 2003-05-21 15:56:36
|
On Wed, 2003-05-21 at 11:08, Cliff Martin wrote: > Hi, >=20 > I have a problem where I want to set values in a 2D array based on=20 > conditions I=E2=80=99ve established. The variables are the NA of the syst= em, its=20 > wavelength and the correct units on the device I=E2=80=99m modeling. Usin= g these=20 > variables I define a variable N. I set up a 512 by 512 array [x,y]. Then=20 > I set up a radius , r =3D x^2 +y^2 and ask it to give me all r=E2=80=99s(= to the=20 > closest integer) <=3D N(the variable I=E2=80=99ve defined above). This gi= ves all=20 > the index values in that radius and then I set all those locations to a=20 > value of 1. After this I do some FFT =E2=80=98s, etc. So how do I do this= in=20 > Numerical Python without having to index through i,j steps which would=20 > be incredibly tedious. This works fairly well in MatLab but I want to=20 > port my program to Python(for lots of reasons). If you=E2=80=99d rather I= write=20 > the MatLab code snippet I can do that. Thanks. >=20 > Cliff Martin I think part of your code looks like this: x,y =3D Numeric.indices((512,512)) r =3D x**2 + y**2 c =3D r < N=20 In numarray you can then say: a[ c ] =3D 1 In Numeric, I think you say: a =3D a.flat c =3D c.flat Numeric.put(a, Numeric.nonzero(c), 1) a.shape =3D (512,512) Todd |