[Numpy-tickets] [NumPy] #905: numpy.loadtxt usecols argument no longer accepts numpy arrays
NumPy
numpy-tickets@scipy....
Thu Sep 4 15:43:44 CDT 2008
#905: numpy.loadtxt usecols argument no longer accepts numpy arrays
-----------------------+----------------------------------------------------
Reporter: rmay | Owner: somebody
Type: defect | Status: new
Priority: normal | Milestone: 1.2.0
Component: numpy.lib | Version: 1.1.1
Severity: normal | Keywords: patch
-----------------------+----------------------------------------------------
t appears that the usecols argument to loadtxt no longer accepts numpy
arrays:
>>>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)
326
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())
>>>data
array([[ 2., 3.],
[ 5., 6.]])
Before the fix and refactoring of loadtxt in 1.1.1, converting to a list
was not necessary. I think the assumptions just kind of cropped in
(exploiting certain list functionality like list.find for ease of code).
I've attached a simple patch against HEAD that does the obvious fix and
converts usecols to a list if it's not None. This should allow almost any
iterable (including tuples, which are also currently broken but used in
the docstring) to be passed in to usecols.
--
Ticket URL: <http://scipy.org/scipy/numpy/ticket/905>
NumPy <http://projects.scipy.org/scipy/numpy>
The fundamental package needed for scientific computing with Python.
More information about the Numpy-tickets
mailing list