[SciPy-dev] Fancy indexing curiosity

Sasha ndarray at mac.com
Mon Jan 9 10:24:50 CST 2006


---------- Forwarded message ----------
From: Alexander Belopolsky <alexander.belopolsky at gmail.com>
Date: Jan 9, 2006 11:21 AM
Subject: Re: [SciPy-dev] Fancy indexing curiosity
To: aisaac at american.edu, SciPy Developers List <scipy-dev at scipy.net>


On 1/9/06, Alan G Isaac <aisaac at american.edu> wrote:
> ...
> This seems quite wrong:
> numpy.core.multiarray.dot([],[]) -> 0
> I expect an exception.

The dot product of two rank-1, length n vectors A and B is
in python notation

    sum(a*b for (a,b) in zip(A, B))

If n = 0, the sum of zero elements is zero.


> Otherwise two empty arrays are judged orthogonal,
> which seems extremely odd.

Why is this odd? These empty arrays are not scalars, they have
dimension 0 and rank 1. They don't have to be orthogonal to have zero
dot product because they have zero norm.

> (Not as odd as the previous behavior, of course.)
> If returning 0 is the right thing to do,
> what is the reason for this being right?

The reason is to avoid a special case. The same definition that works
for non-zero length arrays can be applied to empty sequences and will
yield 0 as I explained above.

-- sasha




More information about the Scipy-dev mailing list