Python 尝试输入时发生UFuncTypeError
当我尝试输入值时,我得到了一个(如下)错误,但当我静态地分配它们时,我不知道为什么 我正在尝试输入inn和out的值。我得到了错误代码,但我真的不知道如何修复它Python 尝试输入时发生UFuncTypeError,python,numpy,matplotlib,Python,Numpy,Matplotlib,当我尝试输入值时,我得到了一个(如下)错误,但当我静态地分配它们时,我不知道为什么 我正在尝试输入inn和out的值。我得到了错误代码,但我真的不知道如何修复它 错误代码: import numpy as np import matplotlib.pyplot as plt inn=.95 out=1.37 n, radii = 50, [inn, out] theta = np.linspace(0, 2*np.pi, n, endpoint=True) xs = np.outer(r
错误代码:
import numpy as np
import matplotlib.pyplot as plt
inn=.95
out=1.37
n, radii = 50, [inn, out]
theta = np.linspace(0, 2*np.pi, n, endpoint=True)
xs = np.outer(radii, np.cos(theta))
ys = np.outer(radii, np.sin(theta))
# in order to have a closed area, the circles
# should be traversed in opposite directions
xs[1,:] = xs[1,::-1]
ys[1,:] = ys[1,::-1]
fig, ax = plt.subplots()
ax = plt.subplot(111, aspect='equal')
ax.fill(np.ravel(xs), np.ravel(ys),color='pink')
star = plt.Circle((0, 0), .25, color='yellow')
earthorbit = plt.Circle((0, 0), 1, color='black', fill=False,linestyle='-',linewidth=2)
inner = plt.Circle((0, 0), inn, color='red', fill=False,linestyle='--',linewidth=2)
outer = plt.Circle((0, 0), out, color='blue', fill=False,linestyle='--',linewidth=2)
ax.add_artist(earthorbit)
ax.add_artist(inner)
ax.add_artist(outer)
ax.set_facecolor('black')
ax.add_artist(star)
plt.show()
import numpy as np
import matplotlib.pyplot as plt
inn=input("Enter inner radial value (in AU): ")
out=input("Enter inner radial value (in AU): ")
n, radii = 50, [inn, out]
theta = np.linspace(0, 2*np.pi, n, endpoint=True)
xs = np.outer(radii, np.cos(theta))
ys = np.outer(radii, np.sin(theta))
# in order to have a closed area, the circles
# should be traversed in opposite directions
xs[1,:] = xs[1,::-1]
ys[1,:] = ys[1,::-1]
fig, ax = plt.subplots()
ax = plt.subplot(111, aspect='equal')
ax.fill(np.ravel(xs), np.ravel(ys),color='pink')
star = plt.Circle((0, 0), .25, color='yellow')
earthorbit = plt.Circle((0, 0), 1, color='black', fill=False,linestyle='-',linewidth=2)
inner = plt.Circle((0, 0), inn, color='red', fill=False,linestyle='--',linewidth=2)
outer = plt.Circle((0, 0), out, color='blue', fill=False,linestyle='--',linewidth=2)
ax.add_artist(earthorbit)
ax.add_artist(inner)
ax.add_artist(outer)
ax.set_facecolor('black')
ax.add_artist(star)
plt.show()
您写入输入的内容将保存为
字符串
值,但我认为您需要浮点
,请尝试以下操作:
inn=float(input("Enter inner radial value (in AU): "))
它的意思是不能将两个字符串数组相乘检查
半径
和θ
。它们真的是数字,还是字符串?啊,它们是字符串,不是吗。我没有这样想。当我这样做时,我得到:文件“C:\Users\sveng\Desktop\HabitableZone.py”,第4行,在inn=int(输入(“输入内径向值(在AU中):”)值错误:int()的文本无效,基数为10:'.95',然后:inn=float(输入(“输入内径向值(在AU中):”)
inn=float(input("Enter inner radial value (in AU): "))