Selecting by sub-data based on algebraic condition

Posted 9 years ago
3469 Views
|
2 Replies
|
3 Total Likes
|
 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?
2 Replies
Sort By:
Posted 9 years ago
 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 TrueGenerally your questions is basic and deserves first of all checking Documentation.
Posted 9 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