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

Adelson Oliveira adelson.oliveira at gmail.com
Sun May 28 03:55:05 CEST 2017


Thanks,

The trick is to create an auxiliar matrix "A" where replics of array "a"
fill the columns and to perform regular elemental multiplications with a
reshaped version of the target hypermatrix "H" and then reshape the result
as original H. It maybe fast because of vectorization but I still have two
questions. This demands addtional memory space if one cannot to do
everything in one step,

and, would it be possible to multiply a line vector "b=(1:5)" to all
lines of "H" or another array

"c" to the third dimension of H in a vectorized way?

Thanks again


2017-05-27 16:19 GMT-03:00 Samuel Gougeon <sgougeon at free.fr>:

> 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));--> R R  = (:,:,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
>
>
>
> _______________________________________________
> users mailing list
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20170527/73f802dc/attachment.htm>


More information about the users mailing list