[Tutor] create numpy array from list of strings
dyoo at cs.wpi.edu
Wed Jun 4 05:24:35 CEST 2008
On Tue, 3 Jun 2008, washakie wrote:
>>> 2) I've done the following, but I doubt it is the most efficient method:
>>> Is there a better way?
>> This looks good.
> Wow, really? I guess I assumed there would be a way to 'nest' list
> comprehension somehow.
I'm assuming you already have good familiarity with list comprehensions.
Given that you've already used to them, if what you're trying to do
doesn't immediately admit a solution with list comprehensions, that's
usually a good mental warning sign: don't!
>> "Danny Yoo-3 wrote:
>> Alhtough it's simple, if you can avoid I/O, do so: touching disk can
>> raise its own problems. I like your second approach much better.
> I know, besides, it certainly seems to slow things down - particularly
> with large arrays / files.
It's because disk access is much slower than memory access. That's why
you want to avoid touching disk unless you really need to: it will kill
your program's performance. Other general reasons include:
* You may need to worry about access control. Do you have write
permission to the tmp directory? Do you care that other people can
* You may accidently fill up the disk.
* Concurrency issue: If two copies of your scripts are running at the
same time, will bad things happen? The 'tmpfile' module tries to
deal with this by making unique names, but it still can be a
> "Danny Yoo-3 wrote:
By the way, I'm flattered. Can I be the new Number 2 next time?
More information about the Tutor