[Numpy-discussion] product of arrays of different lengths

SimonPalmer simon.palmer@gmail....
Mon Sep 15 09:14:04 CDT 2008


what is the overhead associated with importing a new module (whichever
includes izip)?

I am wondering whether it is actually more efficient for me to put my
aesthetics aside and stick with my ugly but efficient loop

On Sep 15, 2:32 pm, Francesc Alted <fal...@pytables.org> wrote:
> A Monday 15 September 2008, Alan G Isaac escrigué:
>
> > On 9/15/2008 6:25 AM Francesc Alted apparently wrote:
> > > max_idx = min(len(A), len(B))
> > > (A[:max_idx] * B[:max_idx]).sum()
>
> > > which does not require a copy becuase the [:max_idx] operator
> > > returns just a view of the arrays.
>
> > But it still requires creating a new array,
> > so perhaps use of ``dot`` above or even::
>
> >    sum(ai*bi for ai,bi in izip(A,B))
>
> > is worth considering in this case.
> > (That is the built-in ``sum``.)
>
> Yeah.  Good point.
>
> --
> Francesc Alted
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discuss...@scipy.orghttp://projects.scipy.org/mailman/listinfo/numpy-discussion


More information about the Numpy-discussion mailing list