[SciPy-User] numpy I/O question

Matwey V. Kornilov matwey.kornilov at gmail.com
Sun Jan 2 11:38:57 EST 2011


Zachary Pincus wrote:

>> Replacement that you described requires O(N) (where N is line
>> length) but
>> C++ operator>> requires O(1) for the same parsing.
> 
> Reading the file into an array is still an O(N) operation, so if all
> you you care about is big-O complexity, there's no difference between
> doing an O(N) search-and-replace followed by an O(N) load operation
> versus an O(1) parsing followed by an O(N) load operation. O(2N) =
> O(N), right?

Yes, You are right. I mixed char-reading and char-inserting operations.

> But if you care about constant factors, why are you even proposing
> regexp matching?

It was 'typing-before-thinking'

>> I will be asked 'why should we use python which even can't parse as
>> good as
>> c++ does?' `sed` isn't a solution.
> 
> This sounds like a personal problem. Sed is a perfectly decent
> solution for reformatting broken text files, as is reformatting the
> files internally to python before passing them to a numpy routine
> designed to be flexible and fast at handling *delimited* text.

It sounds quite reasonable, thank you.





More information about the SciPy-User mailing list