[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sum() behaving erratically?

From: John W. Eaton
Subject: Re: sum() behaving erratically?
Date: Thu, 7 Oct 2004 09:06:41 -0400

On  7-Oct-2004, Bart Vandewoestyne <address@hidden> wrote:

| but actually i think the behaviour as it is is quite intuitive,
| since when a is a vector, then saying sum(a) is just saying that you
| want the sum of all elements of a.  Wether a is a row or a column
| vector doesn't matter than.

Inconsistencies like this are bad design.  If you are working with
matrices that can sometimes be row vectors, you will unexpectedly get
different results.

You will find that Matlab has a number of inconsistencies like this
(diag, all the sum/prod/etc. functions, & and | operators that
short-circuit in IF/WHILE conditions only, and so on).  It would be
nice if Octave could avoid the problems, but experience shows that in
most cases, it is worse to have a language that is almost the same,
but differs in these small details.

| The best thing to do is if you really have a situation where you're
| summing over colums or rows, is *always* put the 1 or 2 as an extra
| argument of sum to indictate if you really want to sum over columns
| or rows.

Yes, that's good advice, but one that seems hard to remember in
practice since it is not enforced.


Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:
How to fund new projects:
Subscription information:

reply via email to

[Prev in Thread] Current Thread [Next in Thread]