Skip to main content
edited title
Link
254
  • 13
  • 4

Sorting each column in a nested list contained in an association

edited body
Source Link
254
  • 13
  • 4
<| 1-> 
{
 {{0.1,2.1},{0.2,-6.4},{0.5,-8.2}},
 {{0.1,4.2},{0.2,0.7}, {0.5,-3.5}},
 {{0.1,5.6},{0.2,5.5}, {0.5,0.2} },
 {{0.1,7.4},{0.2,7.2}, {0.5,3.1} }
},
2-> 
{
 {{0.1,4_3.56}, {0.2,-2.5},{0.5,-7.4}},
 {{0.1,-3.1},{0.2,1.4}, {0.5,0.2} },
 {{0.1,1.3}, {0.2,3.4}, {0.5,4.27}},
 {{0.1,-34.65},{0.2,3.5}, {0.5,5.6} }
},
3-> 
{
 {{0.1,-3.7}, {0.2,1.3},{0.5,-6.2}},
 {{0.1,-1.4},{0.2,3.4}, {0.5,2.4} },
 {{0.1,2.3}, {0.2,5.6}, {0.5,5.4} },
 {{0.1,3.6}, {0.2,7.2}, {0.5,9.1} }
}|>
<| 1-> 
{
 {{0.1,2.1},{0.2,-6.4},{0.5,-8.2}},
 {{0.1,4.2},{0.2,0.7}, {0.5,-3.5}},
 {{0.1,5.6},{0.2,5.5}, {0.5,0.2} },
 {{0.1,7.4},{0.2,7.2}, {0.5,3.1} }
},
2-> 
{
 {{0.1,4.5}, {0.2,-2.5},{0.5,-7.4}},
 {{0.1,-3.1},{0.2,1.4}, {0.5,0.2} },
 {{0.1,1.3}, {0.2,3.4}, {0.5,4.27}},
 {{0.1,-3.6},{0.2,3.5}, {0.5,5.6} }
},
3-> 
{
 {{0.1,-3.7}, {0.2,1.3},{0.5,-6.2}},
 {{0.1,-1.4},{0.2,3.4}, {0.5,2.4} },
 {{0.1,2.3}, {0.2,5.6}, {0.5,5.4} },
 {{0.1,3.6}, {0.2,7.2}, {0.5,9.1} }
}|>
<| 1-> 
{
 {{0.1,2.1},{0.2,-6.4},{0.5,-8.2}},
 {{0.1,4.2},{0.2,0.7}, {0.5,-3.5}},
 {{0.1,5.6},{0.2,5.5}, {0.5,0.2} },
 {{0.1,7.4},{0.2,7.2}, {0.5,3.1} }
},
2-> 
{
 {{0.1,_3.6}, {0.2,-2.5},{0.5,-7.4}},
 {{0.1,-3.1},{0.2,1.4}, {0.5,0.2} },
 {{0.1,1.3}, {0.2,3.4}, {0.5,4.27}},
 {{0.1,4.5},{0.2,3.5}, {0.5,5.6} }
},
3-> 
{
 {{0.1,-3.7}, {0.2,1.3},{0.5,-6.2}},
 {{0.1,-1.4},{0.2,3.4}, {0.5,2.4} },
 {{0.1,2.3}, {0.2,5.6}, {0.5,5.4} },
 {{0.1,3.6}, {0.2,7.2}, {0.5,9.1} }
}|>
added 8 characters in body
Source Link
254
  • 13
  • 4

I want to sort each {x,f_m(x)} in a column in ascending order by f(x), so that the first row will now contains the lowest values of f(x), while the last row will contain the highest. InsteadMoreover, the elements in the row should not change positionstay in their original column, so that all the elements in a column keep having the same value of x.
The rows will then be used to create a function that represents the envelope of the different outcomes of a Monte Carlo method.

<| 1->  
{
 {{0.1,2.1},{0.2,0.7}, {0.5,-3.5}},
 {{0.1,4.2},{0.2,5.5}, {0.5,3.1} },
 {{0.1,5.6},{0.2,-6.4},{0.5,0.2} },
 {{0.1,7.4},{0.2,7.2}, {0.5,-8.2}} 
},
2->  
{
 {{0.1,4.5}, {0.2,3.5}, {0.5,5.6} },
 {{0.1,-3.1},{0.2,1.4}, {0.5,-7.4}},
 {{0.1,1.3}, {0.2,3.4}, {0.5,4.27}},
 {{0.1,-3.6},{0.2,-2.5},{0.5,0.2} } 
},
3->  
{
 {{0.1,3.6}, {0.2,7.2},{0.5,9.1} },
 {{0.1,-1.4},{0.2,1.3},{0.5,5.4} },
 {{0.1,2.3}, {0.2,3.4},{0.5,2.4} },
 {{0.1,-3.7},{0.2,5.6},{0.5,-6.2}}
}|>

and I want to obtain something like this

<| 1-> 
{
 {{0.1,2.1},{0.2,-6.4},{0.5,-8.2}},
 {{0.1,4.2},{0.2,0.7}, {0.5,-3.5}},
 {{0.1,5.6},{0.2,5.5}, {0.5,0.2} },
 {{0.1,7.4},{0.2,7.2}, {0.5,3.1} }
},
2-> 
{
 {{0.1,4.5}, {0.2,-2.5},{0.5,-7.4}},
 {{0.1,-3.1},{0.2,1.4}, {0.5,0.2} },
 {{0.1,1.3}, {0.2,3.4}, {0.5,4.27}},
 {{0.1,-3.6},{0.2,3.5}, {0.5,5.6} }
},
3-> 
{
 {{0.1,-3.7}, {0.2,1.3},{0.5,-6.2}},
 {{0.1,-1.4},{0.2,3.4}, {0.5,2.4} },
 {{0.1,2.3}, {0.2,5.6}, {0.5,5.4} },
 {{0.1,3.6}, {0.2,7.2}, {0.5,9.1} }
}|>

I want to sort each column in ascending order, so that the first row will now contains the lowest values of f(x), while the last row will contain the highest. Instead, the elements in the row should not change position, so that all the elements in a column keep having the same value of x.
The rows will then be used to create a function that represents the envelope of the different outcomes of a Monte Carlo method.

<| 1-> {{{0.1,2.1},{0.2,0.7},{0.5,-3.5}},
{{0.1,4.2},{0.2,5.5},{0.5,3.1}},
{{0.1,5.6},{0.2,-6.4},{0.5,0.2}},
{{0.1,7.4},{0.2,7.2},{0.5,-8.2}}},
2-> {{{0.1,4.5},{0.2,3.5},{0.5,5.6}},
{{0.1,-3.1},{0.2,1.4},{0.5,-7.4}},
{{0.1,1.3},{0.2,3.4},{0.5,4.27}},
{{0.1,-3.6},{0.2,-2.5},{0.5,0.2}}},
3-> {{{0.1,3.6},{0.2,7.2},{0.5,9.1}},
{{0.1,-1.4},{0.2,1.3},{0.5,5.4}},
{{0.1,2.3},{0.2,3.4},{0.5,2.4}},
{{0.1,-3.7},{0.2,5.6},{0.5,-6.2}}}|>

I want to sort each {x,f_m(x)} in a column in ascending order by f(x), so that the first row will now contains the lowest values of f(x), while the last row will contain the highest. Moreover, the elements should stay in their original column, so that all the elements in a column keep having the same value of x.
The rows will then be used to create a function that represents the envelope of the different outcomes of a Monte Carlo method.

<| 1->  
{
 {{0.1,2.1},{0.2,0.7}, {0.5,-3.5}},
 {{0.1,4.2},{0.2,5.5}, {0.5,3.1} },
 {{0.1,5.6},{0.2,-6.4},{0.5,0.2} },
 {{0.1,7.4},{0.2,7.2}, {0.5,-8.2}} 
},
2->  
{
 {{0.1,4.5}, {0.2,3.5}, {0.5,5.6} },
 {{0.1,-3.1},{0.2,1.4}, {0.5,-7.4}},
 {{0.1,1.3}, {0.2,3.4}, {0.5,4.27}},
 {{0.1,-3.6},{0.2,-2.5},{0.5,0.2} } 
},
3->  
{
 {{0.1,3.6}, {0.2,7.2},{0.5,9.1} },
 {{0.1,-1.4},{0.2,1.3},{0.5,5.4} },
 {{0.1,2.3}, {0.2,3.4},{0.5,2.4} },
 {{0.1,-3.7},{0.2,5.6},{0.5,-6.2}}
}|>

and I want to obtain something like this

<| 1-> 
{
 {{0.1,2.1},{0.2,-6.4},{0.5,-8.2}},
 {{0.1,4.2},{0.2,0.7}, {0.5,-3.5}},
 {{0.1,5.6},{0.2,5.5}, {0.5,0.2} },
 {{0.1,7.4},{0.2,7.2}, {0.5,3.1} }
},
2-> 
{
 {{0.1,4.5}, {0.2,-2.5},{0.5,-7.4}},
 {{0.1,-3.1},{0.2,1.4}, {0.5,0.2} },
 {{0.1,1.3}, {0.2,3.4}, {0.5,4.27}},
 {{0.1,-3.6},{0.2,3.5}, {0.5,5.6} }
},
3-> 
{
 {{0.1,-3.7}, {0.2,1.3},{0.5,-6.2}},
 {{0.1,-1.4},{0.2,3.4}, {0.5,2.4} },
 {{0.1,2.3}, {0.2,5.6}, {0.5,5.4} },
 {{0.1,3.6}, {0.2,7.2}, {0.5,9.1} }
}|>
added 8 characters in body
Source Link
254
  • 13
  • 4
Loading
added 37 characters in body
Source Link
254
  • 13
  • 4
Loading
added 37 characters in body
Source Link
254
  • 13
  • 4
Loading
deleted 21 characters in body
Source Link
254
  • 13
  • 4
Loading
added 16 characters in body
Source Link
254
  • 13
  • 4
Loading
added 16 characters in body
Source Link
254
  • 13
  • 4
Loading
Improved formatting
Source Link
m_goldberg
  • 108.1k
  • 16
  • 104
  • 259
Loading
added 16 characters in body
Source Link
254
  • 13
  • 4
Loading
Source Link
254
  • 13
  • 4
Loading