【发布时间】:2019-12-31 02:06:03
【问题描述】:
我不断收到错误:'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,但我不确定现在该做什么。
【问题讨论】:
-
欢迎来到 StackOverflow。请按照您创建此帐户时的建议阅读并遵循帮助文档中的发布指南。 Minimal, complete, verifiable example 适用于此。在您发布 MCVE 代码并准确说明问题之前,我们无法有效地帮助您。我们应该能够将您发布的代码粘贴到文本文件中并重现您指定的问题。包括整个错误消息(包括回溯)并删除多余的代码。
-
听起来您希望
u是一个列表、数组、数据框或类似的东西。但事实并非如此;这是一个浮点数,你不能append()。
标签: python python-3.x python-2.7 python-requests jupyter-notebook