'float'对象没有属性'append'

时间:2019-08-26 21:53:26

标签: python python-3.x python-2.7 python-requests jupyter-notebook

我不断收到错误消息:“ float”对象没有属性“ append”

我不确定从哪里开始,可以从哪里开始,但是当我去运行我的代码时,我总是收到float错误。在我将初始时间更改为1,然后又重新设置为0之前,代码起作用了。

%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
import math

# define da/dt = (u-a)/(tau(a,u))

t0 = 0 #inital time in microseconds
a0 = 0.0 # excitation in volts 
tf = 10 # final time in microseconds
dt = 0.1 # time step size
t_act = 0.75 
t_deact = 0.25

#u = 1.0 # inital excitation value in volts - fix excitation

n = int((tf-t0)/dt+1) #number of samples

# defining t values

t = np.linspace(t0,tf,num=n)

# initalizing array for a and u values

a = np.zeros([n])


#excitation signal allocation


for i in range(1,10):

    u.append(1)

for i in range(11,3000):

    u.append(0)


# loop for euler's method

a[1] = a0


for i in range(1,n):

        a[i] = a[i-1] + dt * (((u[i])/t_act) + ((1 - u[i])/t_deact) * (u[i] - a[i-3]))


# plot solution


plt.plot(t,a, 'o')
plt.xlabel("Value of t in ms")
plt.ylabel("Value of excitation in ")
plt.title("Activation Dynamics")
plt.show()

我希望能画出t&a,但我不确定现在该怎么办。

1 个答案:

答案 0 :(得分:2)

您将u设置为浮点数,然后尝试追加一个您无法对“数字”执行的操作,而是将其最常用于列表,这是什么意思?

u = 1.0

for i in range(1,10):

    u.append(1)

for i in range(11,3000):

    u.append(0)