From: Perry G. <pe...@st...> - 2003-05-21 21:09:30
|
>=20 > x,y =3D Numeric.indices((512,512)) > r =3D x**2 + y**2 > c =3D r < N=20 >=20 > In numarray you can then say: >=20 > a[ c ] =3D 1 >=20 > In Numeric, I think you say: >=20 > a =3D a.flat > c =3D c.flat > Numeric.put(a, Numeric.nonzero(c), 1) > a.shape =3D (512,512) >=20 >=20 > Todd >=20 Yeah, that's what I would do in Numeric :-) I was thinking that the solution I gave was wasteful of memory if N was generally much smaller than the dimensions of data. Something like this (also untested) would be better in that regard (again for numarray) y, x =3D indices((2*N+1, 2*N+1)) yind, xind =3D nonzero(((x-N)**2+(y-N)**2) < N**2)=20 data[yind+y0-N, xind+x0-N] =3D 1 Note that this doesn't check to see if x0 and y0 are at least N away from the boundaries of data, and also note my convention for x and y is different than what Todd used (it depends on how you interpret data in arrays, the convention I use is more common for image data if you think of x corresponding to the most rapidly varying index). The advantage of this approach is that the x and y arrays are small if N is small, and computing xind, yind take much less time than for very large arrays. Doing this with Numeric would be much messier I believe (but a clever person could prove me wrong). Perry Greenfield |