Re: put some elements to zero
- To: mathgroup at smc.vnet.net
 - Subject: [mg101481] Re: put some elements to zero
 - From: pfalloon <pfalloon at gmail.com>
 - Date: Wed, 8 Jul 2009 07:12:10 -0400 (EDT)
 - References: <h2vcj8$qq7$1@smc.vnet.net>
 
On Jul 7, 9:46 pm, Luigi B <L.Balz... at gmail.com> wrote:
> Dear All,
>  I have a matrix with only two columns and many rows. For instance
> {xi,yi}.
> For those xi<x0, I would like to set yi=0.
> I can only think of a very inefficient loop...
>
> thanks
> -Luigi-
One solution is the following:
    x0=0;
    pairs = RandomReal[{-1,1}, {10000,2}];
    pairs = Transpose[pairs];
    pairs = Transpose[{pairs[[1]], UnitStep[pairs[[1]]-x0]*pairs
[[2]]}];
The key is to operate on the entire list rather than individual rows.
Cheers,
Peter.