Mathematica: Reversing sublist

  • Mathematica
  • Thread starter Sarah rob
  • Start date
  • Tags
    Mathematica
In summary, Mathematica is a software used for mathematical and scientific calculations, utilizing the Wolfram Language. To reverse a sublist, you can use the Reverse function or other functions such as Part and Table. To reverse a sublist within a nested list, you can use the Map and Reverse functions together. And finally, to create a reversed copy of a sublist without changing the original list, you can use the Reverse function in combination with the Table function.
  • #1
Sarah rob
16
0
lis= {{{2, 1}, {3, 2}, {8, 2}}, {{9, 6}, {1, 0}, {0, 2}}}

I am trying to reverse the subsublist so {2,1} becomes {1,2}, {3,2} becomes {2,3}...

I have tried Map[Reverse, Flatten[lis, 1]] but this creates
{{1,2},{2,3},{2,8},{6,9},{0,1},{2,0}}
which erases my sublist

Is there a way I can reverse the subsublist and keep all the brakets intact?
 
Physics news on Phys.org
  • #2
You can specify the depth at which you want Map to act. So try

Map[Reverse, lis, {2}]
 

Related to Mathematica: Reversing sublist

1. What is Mathematica and how does it work?

Mathematica is a powerful software that is used for mathematical and scientific calculations. It uses a programming language called Wolfram Language and has a user-friendly interface that allows users to input commands and perform various mathematical operations.

2. How do I reverse a sublist in Mathematica?

To reverse a sublist in Mathematica, you can use the Reverse function. This function takes in a list as its argument and returns the reversed version of the list. You can also specify the sublist you want to reverse by using the Part function, which allows you to select specific elements from a list.

3. Can I reverse a sublist without using the Reverse function?

Yes, you can reverse a sublist using other functions such as Part and Table. The Part function allows you to select specific elements from a list and rearrange them in a different order, while the Table function allows you to create a new list by repeating a certain element or a sequence of elements.

4. How do I reverse a sublist within a nested list in Mathematica?

To reverse a sublist within a nested list, you can use a combination of the Map and Reverse functions. The Map function applies a certain operation to each element of a list, while the Reverse function reverses the elements of a list. By using these two functions together, you can reverse the sublist within a nested list.

5. Can I reverse a sublist in Mathematica without changing the original list?

Yes, you can use the Reverse function in combination with the Table function to create a reversed copy of the sublist without modifying the original list. This is useful when you want to keep the original list intact but still need to work with a reversed version of a sublist.

Similar threads

  • Programming and Computer Science
Replies
5
Views
929
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
496
  • MATLAB, Maple, Mathematica, LaTeX
Replies
22
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
3K
  • Special and General Relativity
Replies
7
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
374
Back
Top