public static SparseVector MeanRowVector(this Matrix<double> matrix)
 {
     SparseVector meanVector = new SparseVector(matrix.RowCount);
     for (int i = 0; i < matrix.RowCount; i++)
     {
         SparseVector row = new SparseVector(SparseVectorStorage<double>.OfVector(matrix.Row(i).Storage));
         double elements = row.NonZerosCount;
         if (elements > 0)
         {
             meanVector[i] = row.Sum() * (1 / elements);
         }
         else
         {
             meanVector[i] = 0;
         }
     }
     return meanVector;
 }
        public static SparseVector MeanColumnVector(this Matrix<double> matrix)
        {
            SparseVector meanVector = new SparseVector(matrix.ColumnCount);
            for (int i = 0; i < matrix.ColumnCount; i++)
            {
                SparseVector column = new SparseVector(SparseVectorStorage<double>.OfVector(matrix.Column(i).Storage));
                double elements = column.NonZerosCount;
                if (elements > 0)
                {
                    double sum = column.Sum();
                    meanVector[i] = sum*(1/elements);
                }
                else
                {
                    meanVector[i] = 0;
                }

            }
            return meanVector;
        }