[Scilab-users] Vectorization

Serge Steer Serge.Steer at inria.fr
Tue Feb 12 17:50:21 CET 2013


You can try something like
// CALCULATE VARIANCE OVER LAST N POINTS

Ni    =    100;
Nj    =    10;
Nk    =    10;

A     =    rand(Ni,Nj,Nk);
tic;
A=matrix(A,Ni,-1);//transform A into a 2D array
D1=zeros(Ni-N+1,Nj*Nk);
for i=N:Ni,
   D1(i-(N-1),:)=variance(A(i-(N-1):i,:),1);
end

D1=matrix(D1,-1,Nj,Nk); //Transform D1 into a 3D array
toc

Are you sure of your variance definition? For me if v is a vector the 
variance of v is computed by sqrt(sum( (v-mean(v))^2))

Serge Steer
INRIA
Le 12/02/2013 17:10, Stéphane Bécu a écrit :
> Hello,
> I have much difficulty to optimize my calculation. It consists of 
> calculating the variance of a vector over last N elements . See 
> the example in the attached file for a 3D matrix. With a PC under 
> windows 7 and scilab 5.3, it needs 40 sec to calculate the variance 
> for a 10*10*1000 matrix. This is too much long since I have much 
> bigger files to work on.
> There must be a way to vectorize the problem but I do not see how ?
> Thanks in advance,
> Stéphane
>
>
> _______________________________________________
> 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/20130212/d2ec5ac2/attachment.htm>


More information about the users mailing list