I think the problem is given in the error message, although it is not very easy to spot:
IndexError: too many indices for array xs = data[:, col["l1" ]]
‘Too many indices’ means you’ve given too many index values. You’ve given 2 values as you’re expecting data to be a 2D array. Numpy is complaining because data
is not 2D (it’s either 1D or None).
This is a bit of a guess – I wonder if one of the filenames you pass to loadfile() points to an empty file, or a badly formatted one? If so, you might get an array returned that is either 1D, or even empty (np.array(None)
does not throw an Error
, so you would never know…). If you want to guard against this failure, you can insert some error checking into your loadfile
function.
I highly recommend in your for
loop inserting:
print(data)
This will work in Python 2.x or 3.x and might reveal the source of the issue. You might well find it is only one value of your outputs_l1
list (i.e. one file) that is giving the issue.