[Numpy-discussion] Sine Distribution on a 2D Array
Christian K.
ckkart@hoc....
Sun Jul 25 02:02:09 CDT 2010
Am 25.07.10 06:38, schrieb Ian Mallett:
> Hi,
>
> So I have a square 2D array, and I want to fill the array with sine
> values. The values need to be generated by their coordinates within the
> array.
>
> The center of the array should be treated as the angle 90 degrees. Each
> of the four edges should be 0 degrees. The corners, therefore, ought to
> be -sqrt(2)*90 degrees. The angle is equal to
> (distance_from_center/(dimension_of_array/2))*90 degrees. Then take the
> sine of this angle.
>
> To describe another way, if the array is treated like a height-field, a
> single mound of the sine wave should just fit inside the array.
>
> Right now, I'm having trouble because I don't know how to operate on an
> array's values based on the index of the values themselves.
Something like that?
The mgrid thing returns two 2D arrays containing the x- and
y-coordinates which are then used to calculate the height field.
In [5]: import numpy as N
In [6]: x,y = N.mgrid[-N.pi/2.0:N.pi/2.0:100j,-N.pi/2.0:N.pi/2.0:100j]
In [7]: z = N.sin(N.sqrt(x**2+y**2))
Christian
More information about the NumPy-Discussion
mailing list