# [Scilab-users] u .^ k ?

4 messages
Open this post in threaded view
|

## [Scilab-users] u .^ k ?

 Hi, Does anyone know how to perform efficiently an operation like : u .^k with: u = [u1, u2, ..., un]  // ui : real numbers and: k = [k1; k2; kp]  // ki : positive integers The result being : [ u1^k1, u2^k1, ..., un^k1;   u1^k2, u2^k2, ..., un^k2; ...   u1^kp, u2^kp, ..., un^kp ] I know  how to do it with cumprod (for instance), but it does not seem to be efficient enough. _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
Open this post in threaded view
|

## Re: u .^ k ?

 Le 19/12/12 11:17, Lamy Alain a écrit : > Hi, > > Does anyone know how to perform efficiently an operation like : > u .^k > > with: > u = [u1, u2, ..., un]  // ui : real numbers > and: > k = [k1; k2; kp]  // ki : positive integers > > > The result being : > > [ u1^k1, u2^k1, ..., un^k1; >    u1^k2, u2^k2, ..., un^k2; > ... >    u1^kp, u2^kp, ..., un^kp ] > > > I know  how to do it with cumprod (for instance), but it does not seem to be > efficient enough. > > > > > > > > > _______________________________________________ > users mailing list > [hidden email] > http://lists.scilab.org/mailman/listinfo/usersmaybe u(ones(1,p),:).^k(:,ones(1,n)) ? S. _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users
 In reply to this post by Alain LAMY On 19/12/2012 11:17, Lamy Alain wrote: ```Hi, Does anyone know how to perform efficiently an operation like : u .^k with: u = [u1, u2, ..., un] // ui : real numbers and: k = [k1; k2; kp] // ki : positive integers The result being : [ u1^k1, u2^k1, ..., un^k1; u1^k2, u2^k2, ..., un^k2; ... u1^kp, u2^kp, ..., un^kp ] I know how to do it with cumprod (for instance), but it does not seem to be efficient enough. ``` Hi I'm not sure you can imagine something more efficient for the general case (arbitrary k's) than: U = ones(1,n)*u; K = ones(1,n)*k; ans = U.^K; ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users ``` _______________________________________________ users mailing list [hidden email] http://lists.scilab.org/mailman/listinfo/users