0
|
4219 Views
|
3 Replies
|
6 Total Likes
View groups...
Share
GROUPS:

# The result of the splitting List is not as expected.

Posted 4 years ago
 The results of the two data are different. Does anyone know the reason?  data1 = {1, 2, 3, 4, 3, 2, 1, 5, 6, 7, 4, 3}; data2 = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 39, 40, 41, 42, 43, 44, 45, 46}; Split[data1, Less] Split[data2, Less] result 1: {{1, 2, 3, 4}, {3}, {2}, {1, 5, 6, 7}, {4}, {3}} result 2: {{5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 39, 40, 41, 42, 43, 44, 45, 46}}  But the answer I want is : Split[data2, Less] = {{5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, {39, 40, 41, 42, 43, 44, 45, 46}} 
3 Replies
Sort By:
Posted 4 years ago
 Split does exactly what is described in the documentation.In data2a you have only True, therefore the whole list is given as result data1 = {1, 2, 3, 4, 3, 2, 1, 5, 6, 7, 4, 3}; data2 = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 39, 40, 41, 42, 43, 44, 45, 46}; data1a = Partition[data1, 2, 1] #[[1]] < #[[2]] & /@ data1a data2a = Partition[data2, 2, 1] #[[1]] < #[[2]] & /@ data2a 
Posted 4 years ago
 In[15]:= data1 = {1, 2, 3, 4, 3, 2, 1, 5, 6, 7, 4, 3}; data2 = {5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 39, 40, 41, 42, 43, 44, 45, 46}; Split[data1, Less] Split[data2, #2 - #1 < 2 &] Out[17]= {{1, 2, 3, 4}, {3}, {2}, {1, 5, 6, 7}, {4}, {3}} Out[18]= {{5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20}, {39, 40, 41, 42, 43, 44, 45, 46}} 
Posted 4 years ago
 Thank Hans Dolhaine & Valeriu Ungureanu.Let me understand the correct way to use Split~~~