श्रेणी स्थितियों के साथ एक सरणी विभाजित करें
मेरे पास निम्नलिखित की तरह एक सरणी है:
sortedransam={{0.105328, -0.0291632}, {0.253571, 0.00498561}, {0.410887,
0.171317}, {1.45579, 0.300952}, {2.56002, -0.0599007}, {3.67651,
0.0913857}, {4.44773, -0.21599}, {4.68098, 0.0766649}, {5.20004,
0.0153934}, {5.31011, 0.157674}, {6.25626, -0.119345}, {6.35928,
0.145992}, {6.52711, -0.0163245}, {7.44436, 0.0334628}, {7.8401,
0.305493}, {8.18541, 0.0712892}, {8.21423, -0.0325363}, {9.0921, -0.0242404}, {9.3285, 0.035512}}
sortedransam
पहले सर्दी को हल कर दिया गया है। मैं इस सरणी को उन शर्तों के साथ विभाजित करना चाहूंगा, जो पहले स्तंभ को पूर्व श्रेणी में रखती हैं। 0-2, 2-4, 4-6 ... फिर जैसा sortedransam
होना चाहिए
{{{0.105328, -0.0291632}, {0.253571, 0.00498561}, {0.410887,
0.171317}, {1.45579, 0.300952}},
{{2.56002, -0.0599007}, {3.67651, 0.0913857}},
{{4.44773, -0.21599}, {4.68098, 0.0766649}, {5.20004, 0.0153934}, {5.31011, 0.157674}},
{{6.25626, -0.119345}, {6.35928, 0.145992}, {6.52711, -0.0163245}, {7.44436, 0.0334628},
{7.8401,0.305493}},
{{8.18541, 0.0712892}, {8.21423, -0.0325363}, {9.0921, -0.0242404}, {9.3285, 0.035512}}}
क्या मुझे उपयोग करना चाहिए SplitBy
या कुछ और? मुझे नहीं पता कि कैसे लागू होने वाली शर्तों को प्राप्त करना है।
जवाब
5 kglr
SplitBy[sortedransam, Quotient[First[#], 2] &]
{{{0.105328, -0.0291632}, {0.253571, 0.00498561}, {0.410887, 0.171317}, {1.45579, 0.300952}}, {{2.56002, -0.0599007}, {3.67651, 0.0913857}}, {{4.44773, -0.21599}, {4.68098, 0.0766649}, {5.20004, 0.0153934}, {5.31011, 0.157674}}, {{6.25626, -0.119345}, {6.35928, 0.145992}, {6.52711, -0.0163245}, {7.44436, 0.0334628}, {7.8401, 0.305493}}, {{8.18541, 0.0712892}, {8.21423, -0.0325363}, {9.0921, -0.0242404}, {9.3285, 0.035512}}}
आप यह भी उपयोग कर सकते हैं BinLists:
Join @@ BinLists[sortedransam, {0, 10, 2}, {-1, 1, 2}]
एक ही परिणाम
4 J.M.'sennui
GatherBy[]
+ के साथ बहुत मुश्किल नहीं है Floor[]
:
GatherBy[sortedransam, Floor[First[#], 2] &]
{{{0.105328, -0.0291632}, {0.253571, 0.00498561}, {0.410887, 0.171317},
{1.45579, 0.300952}},
{{2.56002, -0.0599007}, {3.67651, 0.0913857}},
{{4.44773, -0.21599}, {4.68098, 0.0766649}, {5.20004, 0.0153934},
{5.31011, 0.157674}},
{{6.25626, -0.119345}, {6.35928, 0.145992}, {6.52711, -0.0163245},
{7.44436, 0.0334628}, {7.8401, 0.305493}},
{{8.18541, 0.0712892}, {8.21423, -0.0325363}, {9.0921, -0.0242404},
{9.3285, 0.035512}}}