[Scilab-users] vector product (hyper)matrix and vector

Samuel Gougeon sgougeon at free.fr
Sat May 27 21:19:18 CEST 2017


Hello Adelson,

Le 27/05/2017 à 17:12, Adelson a écrit :
> Hello,
>
> How to obtain the product of a one dimensional array and a hypermatrix in a
> vector way?
>
> I mean, an array a(1:N) times a hypermatrix H(1:M,1:N,1:P,....), for all
> m,p,q,... indices:
>
> for m=1:M
>    for p=1:P
>      for q=.....
>         ....
>             R(m,:,p,q,....) =H(m,:,p,q,...) .* a(:);
>         ....
>      end
>    end
> end
>
> in a vectorized form?
>
> As an example, in FORTRAN one could simply write in a vectorized form,
>
> FORALL(m=1:M,p=1:P,q=...,...); R(m,:,p,q,...)=H(m,:,p,q,....)*a(:);
>
> And, it seems that in MATLAB one could do something similar using the comand
> DOT.


You can use

tmp=matrix(H,size(H,1),-1);R=matrix(tmp.*(a(:)*ones(tmp(1,:))),size(H));Example:
--> H = grand(3,5,2,2,"uin",0,2)H = (:,:,1,1)2. 2. 2. 1. 0.0. 1. 2. 1. 
0.2. 1. 0. 2. 2.(:,:,2,1)0. 1. 1. 0. 0.0. 1. 2. 2. 1.1. 2. 1. 1. 
2.(:,:,1,2)0. 2. 1. 0. 2.0. 0. 2. 0. 0.1. 1. 1. 0. 2.(:,:,2,2)0. 1. 2. 
0. 2.0. 2. 2. 0. 1.1. 1. 0. 1. 2.--> a = (1:3)'a = 1.2.3.--> tmp = 
matrix(H,size(H,1),-1);--> R = matrix(tmp .* (a(:) * ones(tmp(1,:))), 
size(H));--> RR = (:,:,1,1)2. 2. 2. 1. 0.0. 2. 4. 2. 0.6. 3. 0. 6. 
6.(:,:,2,1)0. 1. 1. 0. 0.0. 2. 4. 4. 2.3. 6. 3. 3. 6.(:,:,1,2)0. 2. 1. 
0. 2.0. 0. 4. 0. 0.3. 3. 3. 0. 6.(:,:,2,2)0. 1. 2. 0. 2.0. 4. 4. 0. 2.3. 
3. 0. 3. 6.Samuel


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20170527/7eea3a27/attachment.htm>


More information about the users mailing list