Skip to main content
added 1 character in body
Source Link
george2079
  • 39.3k
  • 1
  • 45
  • 115

using the 2d form of BinLists ( note the first dimension binspec is cooked up so there is just one bin )

 list = RandomReal[{0, 1}, {20}];
 binspec = {0, 1, .1};
 (#[[All, 1]] & /@ First@BinLists[ MapIndexed[{First@#2, #} &, #] ,
       {0, Length@# + 1, Length@# + 1}, binspec]) &@list

{{1, 10, 20}, {6}, {7, 15}, {4}, {5, 12, 17}, {11}, {14, 18}, {9}, {2, 3, 8, 16, 19}, {13}}

 ( list[[#]] & /@ % ) == BinLists[ list , binspec] 

True

You could simply do this as well:

 Union@Flatten@(Position[ list, #]  & /@ # ) & /@ BinLists[list, binspec]

using the 2d form of BinLists ( note the first dimension binspec is cooked up so there is just one bin )

 list = RandomReal[{0, 1}, {20}];
 binspec = {0, 1, .1};
 (#[[All, 1]] & /@ First@BinLists[ MapIndexed[{First@#2, #} &, #] ,
       {0, Length@# + 1, Length@# + 1}, binspec]) &@list

{{1, 10, 20}, {6}, {7, 15}, {4}, {5, 12, 17}, {11}, {14, 18}, {9}, {2, 3, 8, 16, 19}, {13}}

 ( list[[#]] & /@ % ) == BinLists[ list , binspec] 

True

using the 2d form of BinLists ( note the first dimension binspec is cooked up so there is just one bin )

 list = RandomReal[{0, 1}, {20}];
 binspec = {0, 1, .1};
 (#[[All, 1]] & /@ First@BinLists[ MapIndexed[{First@#2, #} &, #] ,
       {0, Length@# + 1, Length@# + 1}, binspec]) &@list

{{1, 10, 20}, {6}, {7, 15}, {4}, {5, 12, 17}, {11}, {14, 18}, {9}, {2, 3, 8, 16, 19}, {13}}

 ( list[[#]] & /@ % ) == BinLists[ list , binspec] 

True

You could simply do this as well:

 Union@Flatten@(Position[ list, #]  & /@ # ) & /@ BinLists[list, binspec]
added 1 character in body
Source Link
george2079
  • 39.3k
  • 1
  • 45
  • 115

using the 2d form of BinLists ( notnote the first dimension binspec is cooked up so there is just one bin )

 list = RandomReal[{0, 1}, {20}];
 binspec = {0, 1, .1};
 (#[[All, 1]] & /@ First@BinLists[ MapIndexed[{First@#2, #} &, #] ,
       {0, Length@# + 1, Length@# + 1}, binspec]) &@list

{{1, 10, 20}, {6}, {7, 15}, {4}, {5, 12, 17}, {11}, {14, 18}, {9}, {2, 3, 8, 16, 19}, {13}}

 ( list[[#]] & /@ % ) == BinLists[ list , binspec] 

True

using the 2d form of BinLists ( not the first dimension binspec is cooked up so there is just one bin )

 list = RandomReal[{0, 1}, {20}];
 binspec = {0, 1, .1};
 (#[[All, 1]] & /@ First@BinLists[ MapIndexed[{First@#2, #} &, #] ,
       {0, Length@# + 1, Length@# + 1}, binspec]) &@list

{{1, 10, 20}, {6}, {7, 15}, {4}, {5, 12, 17}, {11}, {14, 18}, {9}, {2, 3, 8, 16, 19}, {13}}

 ( list[[#]] & /@ % ) == BinLists[ list , binspec] 

True

using the 2d form of BinLists ( note the first dimension binspec is cooked up so there is just one bin )

 list = RandomReal[{0, 1}, {20}];
 binspec = {0, 1, .1};
 (#[[All, 1]] & /@ First@BinLists[ MapIndexed[{First@#2, #} &, #] ,
       {0, Length@# + 1, Length@# + 1}, binspec]) &@list

{{1, 10, 20}, {6}, {7, 15}, {4}, {5, 12, 17}, {11}, {14, 18}, {9}, {2, 3, 8, 16, 19}, {13}}

 ( list[[#]] & /@ % ) == BinLists[ list , binspec] 

True

deleted 40 characters in body
Source Link
george2079
  • 39.3k
  • 1
  • 45
  • 115

using the 2d form of BinLists to effectively create a BinListsBy( not the first dimension binspec is cooked up so there is just one bin ..)

 list = RandomReal[{0, 1}, {20}];
 binspec = {0, 1, .1};
 (#[[All, 1]] & /@ First@BinLists[ MapIndexed[{First@#2, #} &, #] ,
       {0, Length@# + 1, Length@# + 1}, binspec]) &@list

{{1, 10, 20}, {6}, {7, 15}, {4}, {5, 12, 17}, {11}, {14, 18}, {9}, {2, 3, 8, 16, 19}, {13}}

 ( list[[#]] & /@ % ) == BinLists[ list , binspec] 

True

using the 2d form of BinLists to effectively create a BinListsBy ..

 list = RandomReal[{0, 1}, {20}];
 binspec = {0, 1, .1};
 (#[[All, 1]] & /@ First@BinLists[ MapIndexed[{First@#2, #} &, #] ,
       {0, Length@# + 1, Length@# + 1}, binspec]) &@list

{{1, 10, 20}, {6}, {7, 15}, {4}, {5, 12, 17}, {11}, {14, 18}, {9}, {2, 3, 8, 16, 19}, {13}}

 ( list[[#]] & /@ % ) == BinLists[ list , binspec] 

True

using the 2d form of BinLists ( not the first dimension binspec is cooked up so there is just one bin )

 list = RandomReal[{0, 1}, {20}];
 binspec = {0, 1, .1};
 (#[[All, 1]] & /@ First@BinLists[ MapIndexed[{First@#2, #} &, #] ,
       {0, Length@# + 1, Length@# + 1}, binspec]) &@list

{{1, 10, 20}, {6}, {7, 15}, {4}, {5, 12, 17}, {11}, {14, 18}, {9}, {2, 3, 8, 16, 19}, {13}}

 ( list[[#]] & /@ % ) == BinLists[ list , binspec] 

True

Source Link
george2079
  • 39.3k
  • 1
  • 45
  • 115
Loading