0

I would like to work get the C values , which is firstly filled with zeros and would like to get the output from the equation I tried to insert. Yes, a has 5 index included array , which is less than other array. My data of a is true. I would like to get the result anyhow with 6 index included array c. Could you please help me out this? The error I got is

"index 5 is out of bounds for axis 0 with size 5".

import numpy as np
imax = 7
Hp = np.array([0.01, 0.01, 0.01, 0.01, 0.01, 0.01])
T = np.array([0.        , 0.00023364, 0.00059821, 0.00072914, 0.00071593,
       0.00035136])
c_k = np.array([ 0.8977551 , -0.12265306, -0.73489796, -0.93897959, -0.73489796,
       -0.12265306])
b = np.array([0.        , 0.        , 0.66156463, 1.03231293, 0.99489796,
       0.54931973])
a = np.array([-0.        , -0.00023364, -0.00036457, -0.00036457, -0.00035136])
c = np.zeros(imax)
for i in range(1, imax):
    c[i]= Hp[i]+T[i]*c_k[i]+a[i]*c_k[i+1]-b[i]
  • 1
    In your own words: where the code says `for i in range(1, imax):`, what do you think this means? In particular, what do you think will be the values of `i`, each time through the loop? Where the code says `Hp[i]`, what do you think this means? How many elements are there in `Hp`? Therefore, what values of `i` do you think are permissible? (If you can answer all these questions correctly, then the problem should be obvious, and considered a typo. Otherwise, please see the linked duplicate.) – Karl Knechtel Jan 26 '23 at 18:14
  • @Kay_Khaig_Kyaw Welcome to StackOverflow! You should show us the full error message next time. on the error message, it is often written which line of code generated the error, which helps locate it immediately. You should try watching a quick tutorial on [reading python errors](https://www.youtube.com/watch?v=3p3p6kp39to), it will make your life easy-peazy. – Florian Fasmeyer Jan 26 '23 at 18:22

0 Answers0