Re: Using Select

• To: mathgroup at smc.vnet.net
• Subject: [mg97411] Re: [mg97371] Using Select
• From: DrMajorBob <btreat1 at austin.rr.com>
• Date: Thu, 12 Mar 2009 05:43:47 -0500 (EST)
• References: <200903120716.CAA23431@smc.vnet.net>

```For instance:

data = RandomReal[{-1, 0.5}, {17, 10}];
dataEval = Mean /@ data;
Pick[data, dataEval, _?Positive]

{{-0.449982, 0.2009, 0.199709, 0.235786, 0.150056, 0.178905,
0.424249, -0.000534571, -0.742857, 0.202645}, {0.464844,
0.292049, -0.174897, 0.0626164, -0.515538, 0.424741, 0.452547,
0.254448, -0.574943, -0.48209}}

or

Pick[data, Mean /@ data, _?Positive]

{{-0.449982, 0.2009, 0.199709, 0.235786, 0.150056, 0.178905,
0.424249, -0.000534571, -0.742857, 0.202645}, {0.464844,
0.292049, -0.174897, 0.0626164, -0.515538, 0.424741, 0.452547,
0.254448, -0.574943, -0.48209}}

Bobby

On Thu, 12 Mar 2009 02:16:40 -0500, Karsten W.

> Hello,
>
> here is a problem I have solved but I am not happy with the method
>
> I have a data matrix DATA, a list of m ordered n-tuples. I run a
> function on the data matrix which returns a list DATAEVAL with m
> elements. The i-th element of this list corresponds to the i-th tuple
> of the data matrix. I think of this DATAEVAL list as an additional
> column of the data matrix.
>
> Now I am only interested in those tuples of the data matrix, where the
> corresponding DATAEVAL list has a value greater than zero.
>
> My current approach is the following: I add the DATAEVAL list to the
> data matrix and call Select afterwards:
>
> data = Import[...];
> dataEval = f[data, ...];
> filteredData = Select[Transpose[Join[Transpose[data], {dataEval}] ],
> Last[#] > 0 &];
>
> This works. However, calling Transpose two times seems not to be the
> most efficient way to solve the problem.
>
> As a newbie to Mathematica (and functional programming), I wonder if
> you can point me to a simpler solution?
>
> Kind regards,
> Karsten.
>
>
>
>
>

--
DrMajorBob at bigfoot.com

```

• References:
• Using Select