Jumat, 26 Desember 2014

Library Masking Array di C#




Masalah masking array difunctional programming sangat mudah, sebagai contoh pada matlab dan Net (C#)











Matlab



clc;clear all;close all;
a = [1 2 3;4 5 6]
b = [7 8 9;10 11 12]
 
c1 = [a;b] % append baris
c2 = [a b] % append kolom
 
c3 = c1(1:2,1:2) % for selection
 
c4 = c1(1:2,:) %for selection
 
c5 = c1;
c5(c5>=3) = 10 %for where
c6 = zeros(size(c1,1),size(c1,2));
c6(1:2,:) =  c1(1:2,:) %copy
       
 

Perhatikan hasil nya




 a =

     1     2     3
     4     5     6

b =

     7     8     9
    10    11    12

c1 =

     1     2     3
     4     5     6
     7     8     9
    10    11    12

c2 =

     1     2     3     7     8     9
     4     5     6    10    11    12

c3 =

     1     2
     4     5

c4 =

     1     2     3
     4     5     6

c5 =

     1     2    10
    10    10    10
    10    10    10
    10    10    10

c6 =

     1     2     3
     4     5     6
     0     0     0
     0     0     0


       
 

C# / NetPlafform


Kamu bisa bisa melakukan masking array dengan mudah di C# yaitu dengan menggunakan class NumP


double [,] a = new double[,]{{1,2,3},{4,5,6}};
double [,] b = new double[,]{{7,8,9},{10,11,12}};
double [,] c = new double[4,3];
double [,] c1 = NumP.Append(a,b,NumP.HV.Row);
double [,] c2 = NumP.Append(a,b,NumP.HV.Column);
double [,] c3 = NumP.ForCopy(c1,0,1,0,1);
double [,] c4 = NumP.ForCopy(c1,0,1,0,c1.GetLength(1)-1);
double nilaiPengganti = 10;
double [,] c5 = NumP.Where(c1,NumP.WHERE.GreaterOrEqual,3,nilaiPengganti);            
double [,] c6 = new double[c1.GetLength(0),c1.GetLength(1)];
c6 = NumP.ForCopy(c1,c6,0,1,0,c1.GetLength(1)-1);
NumP.PrintConsole(c1);
NumP.PrintConsole(c2);
NumP.PrintConsole(c3);
NumP.PrintConsole(c4);
NumP.PrintConsole(c5);
NumP.PrintConsole(c6);

Download

Posting Komentar