[Numpy-discussion] using loadtxt() for given number of rows?
cimrman3 at ntc.zcu.cz
Mon Feb 14 11:53:49 EST 2011
On Mon, 14 Feb 2011, Stéfan van der Walt wrote:
> Hi Robert
> On Mon, Jan 31, 2011 at 2:39 PM, Robert Cimrman <cimrman3 at ntc.zcu.cz> wrote:
>> It seems to me, that an additional parameter to loadtxt(), say "nrows" or
>> "numrows", would do the job, so that the function does not try reading the
>> entire file. Another possibility would be to raise an exception as it
>> is now, but also to return the data succesfully read so far.
> You can always read chunks of the file into StringIO objects, and pass
> those into loadtxt. I think your request makes sense though, given
> that a person can already skip lines at the top of the file.
Thanks for the tip, Stéfan!
I have solved my problem by using np.fromfile(), as suggested by
Chris Barker, because I know the number of items to read in advance.
I also think that functionality suitable for loadtxt(), so I created the
NumPy ticket 1731.
More information about the NumPy-Discussion