想用python画matlab里的peaks图像,代码如下:
from matplotlib import pyplot as plt
%matplotlib inline
import numpy as np
from mpl_toolkits.mplot3d import Axes3D
import math
fig = plt.figure()
ax = Axes3D(fig)
x = np.arange(-4, 4, 0.1)
y = np.arange(-4, 4, 0.1)
x, y = np.meshgrid(x, y)
z = 3*(1-x)**2*math.exp(-(x**2) - (y+1)**2)- 10*(x/5 - x**3 - y**5)*math.exp
(-x**2-y**2)- 1/3*math.exp(-(x+1)**2 - y**2)
ax.plot_surface(x, y, z, rstride=1, cstride=1, cmap='rainbow')
plt.show()
提示z=3*……一行有错误
File "<ipython-input-68-b290c588444c>", line 13, in <module>
z = 3*(1-x)**2*math.exp(-(x**2) - (y+1)**2)- 10*(x/5 - x**3 - y**5)*math
.exp(-x**2-y**2)- 1/3*math.exp(-(x+1)**2 - y**2)
TypeError: only size-1 arrays can be converted to Python scalars
请问这一行应该怎样改?
--
FROM 115.57.135.*