[SciPy-User] Expected behaviour when upacking values from np.loadtxt

Brendan Arnold brendanarnold at gmail.com
Wed Feb 2 10:03:56 EST 2011


Hi there,

I am having trouble when I read a file with only one line of data, it
seems to not be an array as expected but a numpy float, i.e.

>>> s = StringIO.StringIO('1,2,3\n4,5,6')
>>> a, b, c = np.loadtxt(s, delimiter=',', unpack=True)
>>> a
<type 'numpy.ndarray'>
>>> a = StringIO.StringIO('1,2,3')
>>> a, b, c = np.loadtxt(s, delimiter=',', unpack=True)
>>> type(a)
<type 'numpy.float64'>

Is there a way to ensure that this always returns an array? This is
messing with my code which expects an iterable

Brendan



More information about the SciPy-User mailing list