首页 > 解决方案 > 'float' 对象没有属性 'append'

问题描述

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

我不确定从哪里开始,因为它以前工作,但是当我去运行我的代码时,我不断收到浮动错误。该代码在我将初始时间更改为 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,但我不确定现在该做什么。

标签: pythonpython-3.xpython-2.7python-requestsjupyter-notebook

解决方案


您设置u为浮点数,然后尝试附加,您无法对“数字”执行某些操作,而是最常用于列表,您的意图是什么?

u = 1.0

for i in range(1,10):

    u.append(1)

for i in range(11,3000):

    u.append(0)

推荐阅读