[Numpy-discussion] Broadcasting rules (Ticket 76).

Keith Goodman kwgoodman at gmail.com
Thu Apr 27 09:32:10 CDT 2006


On 4/26/06, Christopher Barker <Chris.Barker at noaa.gov> wrote:
> something that always bit me with MATLAB. If I had a matrix that
> happened to have a dimension of 1, MATLAB would interpret it as a
> vector. I ended up writing functions like "SumColumns" that would check
> if it was a single row vector before calling sum, so that I wouldn't
> suddenly get a scaler result if a matrix happened to have on row.

In Octave or Matlab, all you need to do is sum(x,1). For example:

>> x = rand(1,4)
x =

  0.56755  0.24575  0.53804  0.36521

>> sum(x,1)
ans =

  0.56755  0.24575  0.53804  0.36521




More information about the Numpy-discussion mailing list