On Tue, Jun 9, 2009 at 09:38, David Paul
Reichert<d.p.reich...@sms.ed.ac.uk> wrote:
> Hi,
>
> Numpy let's me define arrays with zero rows and/or
> columns, and that's wanted behaviour from what I have
> read in discussions. However, I can add an array
> with zero rows to an array with one row (but not more),
> resulting in another zero row array, like so:
>
>
> In: a = zeros((4,0))
>
> In: a
> Out: array([], shape=(4, 0), dtype=float64)
>
> In: b = zeros((4,1))
>
> In: b
> Out:
> array([[ 0.],
>        [ 0.],
>        [ 0.],
>        [ 0.]])
>
> In: a + b
> Out: array([], shape=(4, 0), dtype=float64)
>
>
> Is this a bug? This should give a shape mismatch error,
> shouldn't?

No. According to the rules of broadcasting, the axis will match iff
the sizes from each array are the same OR one of them is 1. So (4,1)
will broadcast with (4,0) to result in a (4,0) array.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to