ValueError異常:陣列的具有多於一個元素的真值是不明確的。使用a.any()或a.all()錯誤想要繪製在python一個簡單的函數
我得到取決於積分方法不同的錯誤。該功能在給定單個值時正常工作。
import matplotlib.pyplot as plt
import scipy as sp
import numpy as np
def mass_enc(R):
def int(r): return r**2 * r
return sp.integrate.quad(int, 0, R)
print(mass_enc(10))
t1 = np.arange(0.1, 5.0, 0.1)
plt.plot(t1, mass_enc(t1))
一些意見:如果你問在matplotlib繪製,使用相應的標籤。由於這裏的錯誤與繪圖無關,請移除繪圖部分。如果您報告錯誤,請報告它發生的位置和文件(在這種情況下,它會是numpy)。 – ImportanceOfBeingErnest