我正在尝试执行以下代码:
import numpy as np
import numexpr as ne
def julia(h, w, maxit=20, a=0.0):
x = np.linspace(-1.8, 1.8, w, dtype=np.float32)
y = np.linspace(-1.8, 1.8, h, dtype=np.float32)
xv, yv = np.meshgrid(x, y)
c = xv+yv*1j
z = c
divtime = maxit + np.zeros(z.shape, dtype=np.uint8)
q = np.complex64(0.7885*np.exp(1j*a))
for i in range(maxit):
ne.evaluate('z*z + q', out=z) # line with error
diverge = z*np.conj(z) > 4
div_now = diverge & (divtime == maxit)
divtime[div_now] = i
z[diverge] = 2
return divtime
julia(100, 100)
变量z
和q
均为complex64
类型,但numexpr返回complex128
。有没有办法使它与complex64
值一起使用以提高性能?