Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6945

Re: How to get elements satisfying specific condition from a list

From Murray Eisenberg <murray@math.umass.edu>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: How to get elements satisfying specific condition from a list
Date 2011-12-05 10:31 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jbi6h4$52m$1@smc.vnet.net> (permalink)

Show all headers | View raw


    a = Range[0, 9];
    Select[a, Sqrt[#] > 2 &]
{5, 6, 7, 8, 9}

   b = Table[{x, y}, {x, 1, 6}, {y, 1, 6}];
   Select[Flatten[b, 1], First@# + Last@# > 9 &]
{{4, 6}, {5, 5}, {5, 6}, {6, 4}, {6, 5}, {6, 6}}

For each example, the function doing the work is Select. Its first 
argument is the list from which to select; its second argument is the 
pure function prescribing the condition by which to select.

In the second example, b is a two-dimensional table, so first you use 
Flatten[b, 1] to join all its rows one after the other into a single 
long list of pairs.

On 12/4/11 2:51 AM, e-changb wrote:
> Hi, please help me if you can.. Let
>
> B:= Table[{x, y}, {x, 1, 6}, {y, 1, 6}]
>
> It is clear that B has 36 elements.
>
> I want to get the list of elements satisfying
> 'the first component + second component is bigger than 9'
>
> so that the answer is
>
> {{5,5},{5,6},{6,5},{6,6}}.
>
> In fact, I have no idea for following even simpler problem. : Let A be a set of all natural numbers less than 10. Find every element whose squre root is bigger than 2. (needless to say the answer is {5,6,7,8,9})
>
> Can you help me ?
>

-- 
Murray Eisenberg                     murray@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower      phone 413 549-1020 (H)
University of Massachusetts                413 545-2859 (W)
710 North Pleasant Street            fax   413 545-1801
Amherst, MA 01003-9305

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: How to get elements satisfying specific condition from a list Murray Eisenberg <murray@math.umass.edu> - 2011-12-05 10:31 +0000

csiph-web