- 1

why am I getting vals=[vals[j] for j in usecols] IndexError: list index out of range

Hi this is my code:in my dat file i have 3 columns of data however the 3rd column is not loading when i include it in the code however when i delete it the other 2 columns do show. Thankyou! is there an easier way?? from matplotlib import pyplot as plt import numpy as np import scipy.optimize as opt import pylab my_files=['earthquake_data.dat'] for i in range(1): N=np.loadtxt(my_files[i],dtype=float, unpack=True, skiprows=1, usecols=(0)) Mag=np.loadtxt(my_files[i],dtype=float, unpack=True, skiprows=1, usecols=(1)) Mag_err=np.loadtxt(my_files[i],dtype=float, unpack=True, skiprows=1, usecols=(2))

23rd May 2020, 10:08 PM
Harish
2 Answers
0
Because of you variable - usecols. There are numbers in it which more then in vals (there is nothing at the start of creating) You may use vals = [j for j in usecols] for solving your problen
28th May 2020, 9:14 AM
Dmitriy Maistrenko
Dmitriy Maistrenko - avatar
0
thankyou
24th Oct 2021, 12:03 AM
Harish