Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use ">" and "<" inside "Cases" Mathematica function?

How do I use ">" and "<" inside "Cases" Mathematica function?

E.g., I would like the cases which end in something greater than 2 for the following nested list:

    lst = { {1, 0, 0}, {1, 1, 1}, {1,1,4} }

I would like to do something like

    Cases[lst, {_, _,>2} ] 

What it is the correct way to express ">2" above?

like image 443
fcpenha Avatar asked Jan 22 '26 20:01

fcpenha


2 Answers

The most straightforward fix to your approach is probably

Cases[lst, {_, _, x_ /; x > 2}]

See the documentation for /; or Condition.

like image 189
High Performance Mark Avatar answered Jan 25 '26 11:01

High Performance Mark


Alternatively,

Cases[lst, {_, _, _?(# > 2 &)}]
like image 20
Chris Degnen Avatar answered Jan 25 '26 11:01

Chris Degnen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!