# [SciPy-user] wavevector arrays

Takanobu Amano takanobu.amano@gmail....
Tue Mar 20 08:06:15 CDT 2007

```fftpack.fftshift may be useful for you.

kx_, ky_, kz_ = mgrid[-nx/2:+nx/2+1,-ny/2:+ny/2+1,-nz/2:+nz/2+1]
kx = fftpack.fftshift(kx_)
ky = fftpack.fftshift(ky_)
kz = fftpack.fftshift(kz_)

I'm not sure if this is what you need.

Takanobu

2007/3/20, J Oishi <joishi@amnh.org>:
> Hi,
>
> I am performing a number of 3D FFTs using scipy, and I had a question
> as to how to setup 3 3D arrays of wavevectors, much like one might do
> with mgrid. However, because the FFT returns wavevectors running from
> 0,...,k_c, -k_c, ..., -1 (where k_c is the nyquist wavenumber) I'm
> not sure how to get mgrid to do this.
>
> In 2D, I could create two 1D kx and ky arrays and use meshgrid (for
> an even number of points):
>
> import numpy as N
>
> kx = 2*N.pi/Lx * N.concatenate(N.arange(0,nx/2-1),N.arange(-nx/2, 0))
> ky = 2*N.pi/Ly * N.concatenate(N.arange(0,ny/2-1),N.arange(-ny/2, 0))
>
> kk = meshgrid(kx,ky)
>
> where kk would have a shape (2,ny,nx). However, this (to my
> knowledge) doesn't generalize to 3D.
>
> I'm a total python/scipy neophyte, so any help you could provide
> would be quite appreciated.
>
> thanks,
>
> jeff
> _______________________________________________
> SciPy-user mailing list
> SciPy-user@scipy.org
> http://projects.scipy.org/mailman/listinfo/scipy-user
>
```