[Scilab-users] row-sum of a hyper-matrix without loop

classic Classic list List threaded Threaded
4 messages Options
fujimoto2005 fujimoto2005
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] row-sum of a hyper-matrix without loop

Is it posible to get a 2-dimension matrix y(j,k) =Σ_i x(i,j,k) from 3
dimension hyper- matrix x(i,j,k) without using  k-loop?
If there is such a way, please teach me.

Best regards,
Masahiro Fujimoto




--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: row-sum of a hyper-matrix without loop

Le 24/11/2019 à 19:53, fujimoto2005 a écrit :
Is it posible to get a 2-dimension matrix y(j,k) =Σ_i x(i,j,k) from 3
dimension hyper- matrix x(i,j,k) without using  k-loop?
If there is such a way, please teach me.


--> h = grand(4,3,2,"uin",0,3)
 h  =
(:,:,1)
   0.   0.   2.
   2.   3.   3.
   2.   1.   3.
   1.   1.   1.
(:,:,2)
   0.   3.   1.
   2.   0.   1.
   3.   1.   3.
   0.   2.   3.

--> matrix(sum(h,1),-1,size(h,2))
 ans  =
   5.   9.   6.
   5.   5.   8.

Regards


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: row-sum of a hyper-matrix without loop

Le 24/11/2019 à 20:01, Samuel Gougeon a écrit :
Le 24/11/2019 à 19:53, fujimoto2005 a écrit :
Is it posible to get a 2-dimension matrix y(j,k) =Σ_i x(i,j,k) from 3
dimension hyper- matrix x(i,j,k) without using  k-loop?
If there is such a way, please teach me.

--> h = grand(4,3,2,"uin",0,3)
 h  =
(:,:,1)
   0.   0.   2.
   2.   3.   3.
   2.   1.   3.
   1.   1.   1.
(:,:,2)
   0.   3.   1.
   2.   0.   1.
   3.   1.   3.
   0.   2.   3.

--> matrix(sum(h,1),-1,size(h,2))
 ans  =
   5.   9.   6.
   5.   5.   8.


Sorry, the correct algorithm is

--> h = grand(4,3,2,"uin",0,3)

 h  =
(:,:,1)
   2.   0.   1.
   2.   3.   2.
   0.   0.   2.
   1.   1.   3.
(:,:,2)
   1.   0.   1.
   1.   2.   0.
   3.   3.   1.
   0.   0.   2.

--> matrix(sum(h,1),size(h,2), -1)
 ans  =
   5.   5.
   4.   5.
   8.   4.

Samuel



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
fujimoto2005 fujimoto2005
Reply | Threaded
Open this post in threaded view
|

Re: row-sum of a hyper-matrix without loop

Dear Samuel

Thanks for your answer.

Best regards,
Masahiro Fujimoto



--
Sent from: http://mailinglists.scilab.org/Scilab-users-Mailing-Lists-Archives-f2602246.html
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users