我在运行代码时遇到了一些困难。当我运行它时,总会出现这种错误:
Traceback (most recent call last):
File "C:\Users\zhangjq058\workspace\22222222\src\222.py", line 20, in <module>
x, y = meshgrid(fftfreq(th.shape[0], dx), fftfreq(th.shape[1], dx))
File "C:\Python27\lib\site-packages\numpy\fft\helper.py", line 153, in fftfreq
assert isinstance(n,types.IntType) or isinstance(n, integer)
AssertionError
代码为:
from pylab import *
from numpy import *
N = 100 #lattice points per axis
dt = 1 #time step
dx = 1 #lattice spacing
t = arange(0, 10000*dt, dt) #time
a = 1 #cofficient
epsilon = 100 #cofficient
M = 1.0 #cofficient
every = 100 #dump an image every
phi_0 = 0.5 #initial mean value of the order parameter
noise = 0.1 #initial amplitude of thermal fluctuations in the order parameter
th = phi_0*ones((N, N)) + noise*(rand(N, N) - 0.5) #initial condition
x, y = meshgrid(fftfreq(th.shape[0], dx), fftfreq(th.shape[1], dx))
k2 = (x*x + y*y) #k is a victor in the Fourier space, k2=x^2+y^2
g = lambda th, a: 4*a*th*(1-th)*(1-2*th) #function g
def update(th, dt, a, k2):
return ifft2((fft2(th)-dt*M*k2*fft2(g(th,a)))/(1+2*epsilon*M*dt*k2**2))
for i in range(size(t)):
print t[i]
if mod(i, every)==0:
imshow(abs(th), vmin=0.0, vmax=1.0)
colorbar()
savefig('t'+str(i/every).zfill(3)+'.png', dpi=100)
clf()
th=update(th, dt, a, k2)
答案 0 :(得分:2)
我假设您在Windows 64位下。您的numpy版本中存在一个错误,其中 windows long类型不被识别为int。更新numpy或投射你的形状 手动:
fftfreq(int(th.shape[0]), dx)