Skip to main content
Remove my own definitions in favor of those of the OP
Source Link
Jacob Akkerboom
  • 12.2k
  • 46
  • 82

Maybe something like this

bounds = {0, 2, 3.7, 5};
data = {{1, 1.1, 1}, {2, 1, 2}, {1, 2.3, 1}, {3, 2.2, 2}, {1, 3.5, 
    1}, {4, 3.6, 2}, {1, 4.2, 3}, {2, 4.4, 1}};

ineqFu[a_, b_, max_, expr_, data_] :=
 If[
  a == 0,
  expr <= data[[b]]
  ,
  If[
   b == max,
   data[[a]] < expr
   ,
   data[[a]] < expr <= data[[b]]
   ]
  ]

max = Length@bounds + 1;
tokenizedIneqs = 
  ineqFu[##, max, token, bounds]r] & @@@ 
   Partition[Range[0, max], 2, 1];
funkyTown =
  Which @@@
   (Function@
      Evaluate[Riffle[tokenizedIneqs, Range[max]]] /. 
     token :> #[[2]]);
result = GatherBy[dataGatherBy[s, funkyTown];

We then have

result === output

True

Maybe something like this

bounds = {0, 2, 3.7, 5};
data = {{1, 1.1, 1}, {2, 1, 2}, {1, 2.3, 1}, {3, 2.2, 2}, {1, 3.5, 
    1}, {4, 3.6, 2}, {1, 4.2, 3}, {2, 4.4, 1}};

ineqFu[a_, b_, max_, expr_, data_] :=
 If[
  a == 0,
  expr <= data[[b]]
  ,
  If[
   b == max,
   data[[a]] < expr
   ,
   data[[a]] < expr <= data[[b]]
   ]
  ]

max = Length@bounds + 1;
tokenizedIneqs = 
  ineqFu[##, max, token, bounds] & @@@ 
   Partition[Range[0, max], 2, 1];
funkyTown =
  Which @@@
   (Function@
      Evaluate[Riffle[tokenizedIneqs, Range[max]]] /. 
     token :> #[[2]]);
result = GatherBy[data, funkyTown];

We then have

result === output

True

Maybe something like this

ineqFu[a_, b_, max_, expr_, data_] :=
 If[
  a == 0,
  expr <= data[[b]]
  ,
  If[
   b == max,
   data[[a]] < expr
   ,
   data[[a]] < expr <= data[[b]]
   ]
  ]

max = Length@bounds + 1;
tokenizedIneqs = 
  ineqFu[##, max, token, r] & @@@ 
   Partition[Range[0, max], 2, 1];
funkyTown =
  Which @@@
   (Function@
      Evaluate[Riffle[tokenizedIneqs, Range[max]]] /. 
     token :> #[[2]]);
result = GatherBy[s, funkyTown];

We then have

result === output

True

Made it more clear that the result is `result`
Source Link
Jacob Akkerboom
  • 12.2k
  • 46
  • 82

Maybe something like this

bounds = {0, 2.5, 43.7, 5};
data = {{1, 1.1, 1}, {2, 1, 2}, {1, 2.3, 1}, {3, 2.2, 2}, {1, 3.5, 
    1}, {4, 3.6, 2}, {1, 4.2, 3}, {2, 4.4, 1}, {-4, 
    10.0, -4}, {-5, -20.0, -5}};

ineqFu[a_, b_, max_, expr_, data_] :=
 If[
  a == 0,
  expr <= data[[b]]
  ,
  If[
   b == max,
   data[[a]] < expr
   ,
   data[[a]] < expr <= data[[b]]
   ]
  ]

max = Length@bounds + 1;
tokenizedIneqs = 
  ineqFu[##, max, token, bounds] & @@@ 
   Partition[Range[0, max], 2, 1];
funkyTown =
  Which @@@
   (Function@
      Evaluate[Riffle[tokenizedIneqs, Range[max]]] /. 
     token :> #[[2]]);
result = GatherBy[data, funkyTown];
result[[All, All, 2]]
 

We then have

{{1.1,1,2.3,2.2},{3.5,3.6,4.2,4.4},{10},{-20}}result === output

True

Maybe something like this

bounds = {0, 2.5, 4.5}
data = {{1, 1.1, 1}, {2, 1, 2}, {1, 2.3, 1}, {3, 2.2, 2}, {1, 3.5, 
    1}, {4, 3.6, 2}, {1, 4.2, 3}, {2, 4.4, 1}, {-4, 
    10.0, -4}, {-5, -20.0, -5}};

ineqFu[a_, b_, max_, expr_, data_] :=
 If[
  a == 0,
  expr <= data[[b]]
  ,
  If[
   b == max,
   data[[a]] < expr
   ,
   data[[a]] < expr <= data[[b]]
   ]
  ]

max = Length@bounds + 1;
tokenizedIneqs = 
  ineqFu[##, max, token, bounds] & @@@ 
   Partition[Range[0, max], 2, 1];
funkyTown =
  Which @@@
   (Function@
      Evaluate[Riffle[tokenizedIneqs, Range[max]]] /. 
     token :> #[[2]]);
result = GatherBy[data, funkyTown];
result[[All, All, 2]]
 
{{1.1,1,2.3,2.2},{3.5,3.6,4.2,4.4},{10},{-20}}

Maybe something like this

bounds = {0, 2, 3.7, 5};
data = {{1, 1.1, 1}, {2, 1, 2}, {1, 2.3, 1}, {3, 2.2, 2}, {1, 3.5, 
    1}, {4, 3.6, 2}, {1, 4.2, 3}, {2, 4.4, 1}};

ineqFu[a_, b_, max_, expr_, data_] :=
 If[
  a == 0,
  expr <= data[[b]]
  ,
  If[
   b == max,
   data[[a]] < expr
   ,
   data[[a]] < expr <= data[[b]]
   ]
  ]

max = Length@bounds + 1;
tokenizedIneqs = 
  ineqFu[##, max, token, bounds] & @@@ 
   Partition[Range[0, max], 2, 1];
funkyTown =
  Which @@@
   (Function@
      Evaluate[Riffle[tokenizedIneqs, Range[max]]] /. 
     token :> #[[2]]);
result = GatherBy[data, funkyTown];

We then have

result === output

True

Delete text that was irrelevant
Source Link
Jacob Akkerboom
  • 12.2k
  • 46
  • 82

Maybe something like this

bounds = {0, 2.5, 4.5}
data = {{1, 1.1, 1}, {2, 1, 2}, {1, 2.3, 1}, {3, 2.2, 2}, {1, 3.5, 
    1}, {4, 3.6, 2}, {1, 4.2, 3}, {2, 4.4, 1}, {-4, 
    10, -4.0, -4}, {-5, -20, -5.0, -5}};

ineqFu[a_, b_, max_, expr_, data_] :=
 If[
  a == 0,
  expr <= data[[b]]
  ,
  If[
   b == max,
   data[[a]] < expr
   ,
   data[[a]] < expr <= data[[b]]
   ]
  ]

max = Length@bounds + 1;
tokenizedIneqs = 
  ineqFu[##, max, token, bounds] & @@@ 
   Partition[Range[0, max], 2, 1];
funkyTown =
  Which @@@
  Function@Evaluate[ (Function@
    Which @@ Riffle[tokenizedIneqsEvaluate[Riffle[tokenizedIneqs, Range[max]]] /. 
     token :> #[[2]], Range[max]]];);
result = GatherBy[data, funkyTown];
result[[All, All, 2]]
{{1.1,1,2.3,2.2},{3.5,3.6,4.2,4.4},{10},{-20}}

The following is a method without GatherBy.

Maybe something like this

bounds = {0, 2.5, 4.5}
data = {{1, 1.1, 1}, {2, 1, 2}, {1, 2.3, 1}, {3, 2.2, 2}, {1, 3.5, 
    1}, {4, 3.6, 2}, {1, 4.2, 3}, {2, 4.4, 1}, {-4, 
    10, -4, -4}, {-5, -20, -5, -5}};

ineqFu[a_, b_, max_, expr_, data_] :=
 If[
  a == 0,
  expr <= data[[b]]
  ,
  If[
   b == max,
   data[[a]] < expr
   ,
   data[[a]] < expr <= data[[b]]
   ]
  ]

max = Length@bounds + 1;
tokenizedIneqs = 
  ineqFu[##, max, token, bounds] & @@@ 
   Partition[Range[0, max], 2, 1];
funkyTown = 
  Function@Evaluate[
    Which @@ Riffle[tokenizedIneqs /. token :> #[[2]], Range[max]]];
result = GatherBy[data, funkyTown];
result[[All, All, 2]]
{{1.1,1,2.3,2.2},{3.5,3.6,4.2,4.4},{10},{-20}}

The following is a method without GatherBy.

Maybe something like this

bounds = {0, 2.5, 4.5}
data = {{1, 1.1, 1}, {2, 1, 2}, {1, 2.3, 1}, {3, 2.2, 2}, {1, 3.5, 
    1}, {4, 3.6, 2}, {1, 4.2, 3}, {2, 4.4, 1}, {-4, 
    10.0, -4}, {-5, -20.0, -5}};

ineqFu[a_, b_, max_, expr_, data_] :=
 If[
  a == 0,
  expr <= data[[b]]
  ,
  If[
   b == max,
   data[[a]] < expr
   ,
   data[[a]] < expr <= data[[b]]
   ]
  ]

max = Length@bounds + 1;
tokenizedIneqs = 
  ineqFu[##, max, token, bounds] & @@@ 
   Partition[Range[0, max], 2, 1];
funkyTown =
  Which @@@
   (Function@
      Evaluate[Riffle[tokenizedIneqs, Range[max]]] /. 
     token :> #[[2]]);
result = GatherBy[data, funkyTown];
result[[All, All, 2]]
{{1.1,1,2.3,2.2},{3.5,3.6,4.2,4.4},{10},{-20}}
RuleDelayed instead of Rule
Source Link
Jacob Akkerboom
  • 12.2k
  • 46
  • 82
Loading
Source Link
Jacob Akkerboom
  • 12.2k
  • 46
  • 82
Loading