【发布时间】:2015-02-10 06:51:34
【问题描述】:
这是我目前写的代码: 我对 python 很陌生,所以我正在尝试使用最基本的方法来实现目标,因为我目前不知道如何提高效率等。
def simulateBeamRun(personlist, beam, times):
times = np.linspace(0,35,500)
templist = []
maxdeflectionlist = []
for t in times:
for i in personlist: #for each person instance
Tuple = personModel.person.loadDisplacement(t)
if 0 < Tuple(1) < beamModel.beam.L:
templist.append(Tuple)
else:
pass
return templist
文件“beamSimulation.py”,第 40 行,在模拟BeamRun 中 元组 = personModel.person.loadDisplacement(t)
我得到的错误是:
TypeError: unbound method loadDisplacement() must be called with person instance as first argument (got float64 instance instead)
personlist 是一个列表列表,每个列表都包含给定“人”的到达时间、体重、步态、速度。这是为了给构造函数赋值。负载位移是 person 类中唯一的其他函数:
class person(object):
"""This class models the displacement of a person's load as they run at
'speed' in one dimension. It assumes that the load is always concentrated
in a single point and that the displacement of that point is less than or
equal to the displacement of the person's centre of mass. Also the
displacement of the load will always be a multiple of 'gait'.
"""
def __init__(self, arrivalTime, weight, gait, speed):
"""This constructor function defines the person's weight, gait and
running speed as well as the time that they arrive at the position of
zero displacement.
"""
我该如何解决这个问题?
【问题讨论】: