Message Boards Message Boards

0
|
3948 Views
|
2 Replies
|
3 Total Likes
View groups...
Share
Share this post:

Selecting by sub-data based on algebraic condition

Posted 10 years ago

Let's say my array of

data = {{x1, y1},{x2,y2},....{xn,yn}}

I want to find the number of elements in my array such that these elements have a yi value with designated bounds. E.g. Find all yi such that 1< yi1, yi2, yi3, ... etc < 2. How do I code this?

POSTED BY: Teddy Ong
2 Replies

There are many possible ways. Priyan's method is essential but many other ways could be made up. Depending on your data quickness of computations may play important role.

data = RandomReal[4, {10^7, 2}];

method1 = Cases[data, x_ /; 1 < x[[2]] < 2]; // AbsoluteTiming
method2 = Select[data, 1 < #[[2]] < 2 &]; // AbsoluteTiming
method3 = Pick[data, IntervalMemberQ[Interval[{1, 2}], data[[All, 2]]]]; // AbsoluteTiming

{21.470108, Null}

{17.848240, Null}

{27.011183, Null}

method1 == method2 == method3

True

Generally your questions is basic and deserves first of all checking Documentation.

POSTED BY: Vitaliy Kaurov
Posted 10 years ago

Here is some code:

data = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
lower = 4;
upper = 6;
selection = Select[data[[All, 2]], # >= lower && # <= upper &];
Length@selection
POSTED BY: Priyan Fernando
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract