Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #6942 > unrolled thread
| Started by | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| First post | 2011-12-05 10:28 +0000 |
| Last post | 2011-12-05 10:28 +0000 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.soft-sys.math.mathematica
Re: How to get elements satisfying specific condition from a list Bob Hanlon <hanlonr357@gmail.com> - 2011-12-05 10:28 +0000
| From | Bob Hanlon <hanlonr357@gmail.com> |
|---|---|
| Date | 2011-12-05 10:28 +0000 |
| Subject | Re: How to get elements satisfying specific condition from a list |
| Message-ID | <jbi6ce$51b$1@smc.vnet.net> |
Avoid using initial capital letters for variable names. Use Set ( = )
rather than SetDelayed ( := ) for defining something that will not
change from one call to the next. Select and Cases are equivalent for
these simple examples:
b = Table[{x, y}, {x, 1, 6}, {y, 1, 6}];
Select[Flatten[b, 1], Total[#] > 9 &]
{{4, 6}, {5, 5}, {5, 6}, {6, 4}, {6, 5}, {6, 6}}
Cases[Flatten[b, 1], _?(Total[#] > 9 &)]
{{4, 6}, {5, 5}, {5, 6}, {6, 4}, {6, 5}, {6, 6}}
Select[Range[9], Sqrt[#] > 2 &]
{5, 6, 7, 8, 9}
Cases[Range[9], _?(Sqrt[#] > 2 &)]
{5, 6, 7, 8, 9}
However, Sqrt[#] > 2& is more simplely written as # > 4&
Bob Hanlon
On Sun, Dec 4, 2011 at 2:51 AM, e-changb <e-changb@hanmail.net> 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 ?
>
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web