- 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))
2 Respostas
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
0
thankyou