>From Insert in Dictionary:
 
    If y has no items (that is, 0=#y), the result of u/y is the 
    neutral or identity element of the function u.
 
Basic Characteristics (b.) gives the identity functions
 
   b=. 3 : '".y,'' b. 1'''
   (,. b&.>) +`*`+.`*.`>.`<.
+--+----------+
|+ |0 $~ [EMAIL PROTECTED] |
+--+----------+
|* |1 $~ [EMAIL PROTECTED] |
+--+----------+
|+.|0 $~ [EMAIL PROTECTED] |
+--+----------+
|*.|1 $~ [EMAIL PROTECTED] |
+--+----------+
|>.|__ $~ [EMAIL PROTECTED]|
+--+----------+
|<.|_ $~ [EMAIL PROTECTED] |
+--+----------+
   +/0 2 3$0
0 0 0
0 0 0
   >./0 2 3$0
__ __ __
__ __ __

If you were to implement Insert, it would use
the identity element as initializer:
 
ins=: 1 : 0
  ".'id=.',u b. 1
  r=. id y
  for_i. |.y do. r=. i u r end.
)
 
   + ins 1 2 3
6
   + ins ''
0
   + ins i.3 4
12 15 18 21
   +/ i.3 4
12 15 18 21
   + ins 3 4$0
0 0 0 0
   +/ 3 4$0
0 0 0 0


----- Original Message ----
From: Anssi Seppälä <[EMAIL PROTECTED]>
To: Programming forum <[email protected]>
Sent: Sunday, July 9, 2006 12:23:00 PM
Subject: [Jprogramming] Sum of empty vector


Working with practical statistics and samples that can be also empty 
I find  that J follows a kind of logic that is uncomfortable. Taking 
a empty vector 0$0 (empty sample) :

    +/0$0    NB. sum of empty sample is zero !
0

    (+/ % #) 0$0    NB. mean of empty sample is also zero !
0

I wonder why (+/0$0)  could not be 0$0 instead of 0 ?

Anssi

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to