[Numpy-discussion] BUG in numpy.loadtxt?

Ryan May rmay31@gmail....
Thu Sep 4 13:08:17 CDT 2008

Stefan (or anyone else who can comment),

It appears that the usecols argument to loadtxt no longer accepts numpy 

 >>>from StringIO import StringIO
 >>>text = StringIO('1 2 3\n4 5 6\n')
 >>>data = np.loadtxt(text, usecols=np.arange(1,3))

ValueError                                Traceback (most recent call last)

/usr/lib64/python2.5/site-packages/numpy/lib/io.py in loadtxt(fname, 
dtype, comments, delimiter, converters, skiprows, usecols, unpack)
     323         first_line = fh.readline()
     324         first_vals = split_line(first_line)
--> 325     N = len(usecols or first_vals)
     327     dtype_types = flatten_dtype(dtype)

ValueError: The truth value of an array with more than one element is 
ambiguous. Use a.any() or a.all()

 >>>data = np.loadtxt(text, usecols=np.arange(1,3).tolist())
array([[ 2.,  3.],
        [ 5.,  6.]])

Was it a conscious design decision that the usecols no longer accept 
arrays? The new behavior (in 1.1.1) breaks existing code that one of my 
colleagues has.  Can we get a patch in before 1.2 to get this working 
with arrays again?



Ryan May
Graduate Research Assistant
School of Meteorology
University of Oklahoma

More information about the Numpy-discussion mailing list