我在運行代碼時遇到了一些困難。當我運行它,這種錯誤總是出現:調用傅立葉變換代碼時出現Python錯誤
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)
請編輯這個職位,並重新發布代碼,選擇它,然後單擊**'{}'**(代碼格式)按鈕,而不是雙 - 放寬每一條線。 –
我無法重現錯誤。 –
我也不能在Python 2.7.6,Fedora 19上;你能分享你的設置嗎? –