The code:
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
r = np.linspace(0.02, 0.98, 10)
theta = np.linspace(0, 2*np.pi)
rgrid, thetagrid = np.meshgrid(r, theta)
xgrid, ygrid = rgrid*np.cos(thetagrid), rgrid*np.sin(thetagrid)
def get_zvalue(r):
if r<0.03:
return 0
elif r>0.02:
delta_s = 0.02/np.sqrt(1-(r-0.02)**2)
return delta_s + get_zvalue(r-0.02)
zsurface = get_zvalue(r)
fig = plt.figure()
ax = fig.gca(projection='3d')
surf = ax.plot_surface(xgrid, ygrid, zsurface)
plt.savefig("Hoops.png")
The error:
ValueError: The truth value of an array with more than one element is
ambiguous. Use a.any() or a.all()
The ValueError is triggered by the line, "if r<0.03:" in the function get_zvalue. I haven't done much with numpy and don't know what to make of this error. Is there any other way to create the zsurface array without getting the error?
ris an array, thenr<0.3is also an array.ifexpects one True/False value. It can't work with an array of them.