[Scilab-users] row-sum of a hyper-matrix without loop
Samuel Gougeon
sgougeon at free.fr
Sun Nov 24 20:09:44 CET 2019
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20191124/71e511b5/attachment.htm>
More information about the users
mailing list