IndexError:索引1超出轴0的大小为1的Python

时间:2018-01-31 17:11:34

标签: python arrays numpy index-error

我试图运行此代码

import numpy as np

import matplotlib.pyplot as plt

"""Script for investigating the different carbon sinks function for 1 unit emission"""

start_year=1                # Model Start Date
end_year=100000              # End date
dt=1                        # Incremented time
time=[start_year,end_year,dt] # Time variable
N=len(time)              # Number of increments 

E=1

tauC=50
tauC_fat=[30,300,10000]


C=np.zeros((1,N))            # CO2 Concentration
C_fat=np.zeros((1,N))
C0=0
C[1]=C0
C_fat[1]=C0


dC=np.zeros((1,N-1))
dC_fat=np.zeros((1,N-1))

fraction=[0.5,0.3,0.2]
dC_frac=np.zeros((1,len(fraction)))
dC_memory=np.zeros((1,len(fraction)))

for n in range (1,N-1):

        if n>1:

            E=0
        dC[n]=(E-C[n]/tauC)*dt

        for m in range(1,3):

                dC_frac[m]=fraction[m]*E-dC_memory[m]/(tauC_fat[m])
                dC_memory[m]=dC_memory[m]+dC_frac[m]*dt
                dC_fat[n]=dC_fat[n]+dC_frac[m]*dt


        C[n+1]=C[n]+dC[n]
        C_fat[n+1]=C_fat[n]+dC_fat[n]

plt.xlabel('Years')
plt.ylabel('ppmv')
plt.title('Fig 5')
plt.legend('Original Model', 'Adapted Model')`

由于我想将这些不同的模型相互映射,但我不断收到错误消息C [1] = C0

IndexError:索引1超出了轴0的大小为1的范围。

我对python很陌生,在这种情况下我无法确定将变量C [1]定义为零的错误是什么?我需要为此运行创建一个数组吗?非常感谢任何帮助。

0 个答案:

没有答案