【发布时间】:2019-01-11 15:18:29
【问题描述】:
当我编译以下程序时,Python 会抛出 TypeError: only integer scalar arrays can be convert to a scalar index.
这似乎是一个相对简单的程序执行,但我似乎无法解决它。
频率
import matplotlib.pyplot as plt
import numpy as np
def period(n):
#masses
m = [1] * n
#lengths
l = [2] * n
M = sum(m)
num = 2 * math.pi * n
for i in range(n):
dem = dem + math.sqrt(g * m[i]/(l[i] * M))
return num/dem
x = np.arange(1, 10,1)
y = period(x)
plt.plot(x,y)
plt.show()
让M == sum from j==1 to n of the masses m_j。我希望该程序仅显示period 的图,其中period(n) 仅由1 到n 的sqrt(g * m_j/(l_j * M)) 之和定义。
【问题讨论】:
标签: arrays python-3.x list physics