[Numpy-discussion] product of arrays of different lengths

Gael Varoquaux gael.varoquaux@normalesup....
Mon Sep 15 09:38:30 CDT 2008


On Mon, Sep 15, 2008 at 07:14:04AM -0700, SimonPalmer wrote:
> what is the overhead associated with importing a new module (whichever
> includes izip)?

Modules are cached, so the cost of importing a module, when it has
already been loaded, is simply the cost of checking if it has been
loaded, and copying the references to the variables in the locals
namespace.

Changes are izip has already been loaded, so the overhead is going to be
relly low. Don't put the import statement in the inner loop, so as not to
have this overhead while running the loop. Put it at the module level, so
as to have it only once.

By the way, speed question are not something one should consider from
prior knowledge, at least not too much, because it is so easy to get it
wrong. Just use the "%timeit" magic of IPython to check for yourself, and
when you have different approaches in mind, see which one is the fastest.

HTH,

Gaël


More information about the Numpy-discussion mailing list