Python Forum
IndexError: index out of bounds for axis 1
Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
IndexError: index out of bounds for axis 1
#1
Getting the error:
return self._RDMS_data[0:, channel_index]
IndexError: index 840 is out of bounds for axis 1 with size 840


The class RDMSDictionary is where the data is read in, and class Pdfs is where I am trying to access and get the IndexError.

Any help is greatly appreciated!

class RDMSDictionary(collections.abc.Mapping):

   def __init__(self, RDMS1, RDMS2, RDMS3, RDMS4, RDMS5, RDMS6, RDMS7, channel_file):
       RDMS_data = self._RDMSfile_data(RDMS1, RDMS2, RDMS3, RDMS4, RDMS5, RDMS6, RDMS7)
       RDMS_channel = self._RDMS_channels(channel_file)
       self._RDMS_data = RDMS_data
       self._RDMS_channel = RDMS_channel
       
   def _RDMSfile_data(self, file1, file2, file3, file4, file5, file6, file7):
       data1 = np.loadtxt(file1, delimiter = '\t', skiprows = 1)
       data1 = np.delete(data1, [0], axis = 1)
       data2 = np.loadtxt(file2, delimiter = '\t', skiprows = 1)
       data2 = np.delete(data2, [0], axis = 1)
       data3 = np.loadtxt(file3, delimiter = '\t', skiprows = 1)
       data3 = np.delete(data3, [0], axis = 1)
       data4 = np.loadtxt(file4, delimiter = '\t', skiprows = 1)
       data4 = np.delete(data4, [0], axis = 1)
       data5 = np.loadtxt(file5, delimiter = '\t', skiprows = 1)
       data5 = np.delete(data5, [0], axis = 1)
       data6 = np.loadtxt(file6, delimiter = '\t', skiprows = 1)
       data6 = np.delete(data6, [0], axis = 1)
       data7 = np.loadtxt(file7, delimiter = '\t', skiprows = 1)
       data7 = np.delete(data7, [0], axis = 1)
       RDMS_data_array = np.concatenate((data1, data2, data3, data4, data5, data6, data7), axis = 1)
       return RDMS_data_array
   
   def _RDMS_channels(self, channel_filename):
       with open(channel_filename, 'r') as cfile:
           self._RDMS_channel = []
           for line in cfile:
               tokens = line.strip().split('\t')
               self._RDMS_channel.append(tokens[0])
           return self._RDMS_channel
       
   
   def __getitem__(self, channel):
       if channel in self._RDMS_channel:
           channel_index = self._RDMS_channel.index(channel)
           return self._RDMS_data[0:, channel_index]
       else: raise KeyError("Channel entered is not in list of channels")
       
   def __len__(self):
       return len(self._RDMS_channel)
   
   def __iter__(self):
       return (x for x in self._RDMS_channel)
class Pdfs:
   
   def __init__(self, RDMS_pdf_name):
       RDMS_pdf = self._RDMS_pdf(RDMS_pdf_name)
       self._RDMS_pdf = RDMS_pdf
       
   def _RDMS_pdf(self, pdf_name):

       with PdfPages(pdf_name) as pdf:
           current_channel = iter(RDMSdict)
           n = dictionary._sample_size(key_filename) * dictionary._revolutions(etim_filename)
           for x in range(len(RDMSdict._RDMS_channels(RDMSchannels))):
                   current = next(current_channel)
                   plt.plot(range(0,n), RDMSdict[current], ':', linewidth = 0.25)
                   pdf.savefig()
                   plt.close() 
    RDMSfile1 = "R33P10_RDMS_Time1.txt"
    RDMSfile2 = "R33P10_RDMS_Time2.txt"
    RDMSfile3 = "R33P10_RDMS_Time3.txt"
    RDMSfile4 = "R33P10_RDMS_Time4.txt"
    RDMSfile5 = "R33P10_RDMS_Time5.txt"
    RDMSfile6 = "R33P10_RDMS_Time6.txt"
    RDMSfile7 = "R33P10_RDMS_Time7.txt"
    RDMSchannels = "R33P10_RDMS_channels.txt"
    RDMSdict = RDMSDictionary(RDMSfile1, RDMSfile2, RDMSfile3, RDMSfile4, RDMSfile5, RDMSfile6, RDMSfile7, RDMSchannels)
    
    pdf_name_RDMSfile = 'Data Comparison RDMS Files.pdf'
    create_pdfs= Pdfs(pdf_name_RDMSfile)  
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  IndexError: index 10 is out of bounds for axis 0 with size 10 Mehboob 11 2,118 Sep-14-2023, 06:54 AM
Last Post: Mehboob
Exclamation IndexError: Replacement index 2 out of range for positional args tuple - help? MrKnd94 2 6,405 Oct-14-2022, 09:57 PM
Last Post: MrKnd94
  IndexError: list index out of range dolac 4 1,924 Jul-25-2022, 03:42 PM
Last Post: deanhystad
  IndexError: list index out of range Anldra12 2 1,448 May-03-2022, 01:39 PM
Last Post: Anldra12
  For loop index out of bounds armitron121 2 2,685 Feb-08-2022, 04:23 PM
Last Post: armitron121
  Sample labels from excel file in order to put them on x-axis and y-axis of a plot hobbyist 11 4,394 Sep-14-2021, 08:29 AM
Last Post: hobbyist
  IndexError: list index out of range rf_kartal 6 2,862 Sep-07-2021, 02:36 PM
Last Post: Larz60+
  IndexError: list index out of range Laplace12 1 2,233 Jun-22-2021, 10:47 AM
Last Post: Yoriz
  IndexError: list index out of range brunolelli 11 6,576 Mar-25-2021, 11:36 PM
Last Post: brunolelli
  IndexError: list index out of range ramu4651 2 3,755 Jan-24-2021, 01:45 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020