python - '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,但我不确定现在该做什么。
解决方案
您设置u
为浮点数,然后尝试附加,您无法对“数字”执行某些操作,而是最常用于列表,您的意图是什么?
u = 1.0
for i in range(1,10):
u.append(1)
for i in range(11,3000):
u.append(0)
推荐阅读
- google-kubernetes-engine - GKE system pods gke-metrics-agent OOMKilld
- java - 如何通过kafka中的java获取特定主题的消费者数量
- excel - CAC graph and calculation
- azure-iot-hub - Regenerate Azure IoT Edge hub certificate
- c++ - 您可以显式使用构造函数重载吗?
- asp.net - 如何将列表作为角度服务中搜索的参数发送到.net核心
- r - For循环仅返回R中的最后一个值
- vue.js - XState 不会停留在空闲状态
- selenium - 如何在谷歌 colab 中运行 chrome webdriver?
- php - 我可以通过 POST PHP 传递一个名称 + 一个 var