[Scilab-users] undocumented behavior of sum(), prod() and type()

Samuel Gougeon sgougeon at free.fr
Tue Feb 11 11:04:35 CET 2020


Le 11/02/2020 à 02:37, Federico Miyara a écrit :
>
> Thanks, Samuel.
>
> This certainly clarifies how [] behaves. But is there a rationale for 
> sum([])==0 and yet cumsum([])==[]?

For sum([])==0 :
IMO this is OK. Personnaly, i expect from
sum(A) + sum(B) + .. sum(Z) not to be killed just because one of the 
arguments is []. So, to me, this case is somewhat distinct from the  A 
+[]. A + [] works element-wise.
Because a vector is expected from sum([],"r"), that then would be added 
in an element-wise way,
--> sum([],"r")
  ans  =
     []
is also OK.

I would give the same rationale for prod([])==1.

> By the way, it would be useful to include cumsum and cumprod among the 
> examples,

Right

Regards
Samuel


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20200211/d9f091e7/attachment.htm>


More information about the users mailing list