Example #1
0
 public static bool contains_only <T, U, V>(Narray <T> a, U value1, V value2)
 {
     for (int i = 0; i < a.Length1d(); i++)
     {
         if (!a.At1d(i).Equals(value1) && !a.At1d(i).Equals(value2))
         {
             return(false);
         }
     }
     return(true);
 }
Example #2
0
        public static double Sum <T>(Narray <T> data)
        {
            double result = 0.0;
            int    n      = data.Length1d();

            for (int i = 0; i < n; i++)
            {
                result += Convert.ToDouble(data.At1d(i));
            }
            return(result);
        }
Example #3
0
        public static float Median(Narray <int> a)
        {
            Narray <int> s = new Narray <int>();

            s.Copy(a);
            s.Reshape(s.Length1d());
            Quicksort(s);
            int n = s.Length();

            if (n == 0)
            {
                return(0);
            }
            if ((n % 2) > 0)
            {
                return(s[n / 2]);
            }
            else
            {
                return((s[n / 2 - 1] + s[n / 2]) / 2.0f);
            }
        }