Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8754933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:44:29+00:00 2026-06-13T13:44:29+00:00

This is a basic question on list manipulation in Mathematica. I have a large

  • 0

This is a basic question on list manipulation in Mathematica.
I have a large list where each element has the following schematic form: {List1, List2,Number}. For e.g.,

a = {{{1,2,3},{1,3,2},5},{{1,4,5},{1,0,2},10},{{4,5,3},{8,3,4},15}}}.

I want to make a new lists which only has some parts from each sublist. Eg., pick out the third element from each sublist to give {5,10,15} from the above. Or drop the third element to return {{{1,2,3},{1,3,2}},{{1,4,5},{1,0,2}},{{4,5,3},{8,3,4}}}.

I can do this by using the table command to construct new lists, e.g.,

Table[a[[i]][[3]],{i,1,Length[a]}

but I was wondering if there was a must faster way which would work on large lists.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T13:44:30+00:00Added an answer on June 13, 2026 at 1:44 pm

    In Mathematica version 5 and higher, you can use the keyword All in multiple ways to specify a list traversal.

    For instance, instead of your Table, you can write

    a[[All,3]]
    

    Here Mathematica converts All into all acceptable indices for the first dimension then takes the 3rd one of the next dimension.

    It is usually more efficient to do this than to make a loop with the Mathematica programming language. It is really fine for homogenous lists where the things you want to pick or scan through always exist.

    Another efficient notation and shortcut is the ;; syntax:

    a[[ All, 1 ;; 2]]
    

    will scan the first level of a and take everything from the 1st to the 2st element of each sublist, exactly like your second case.

    In fact All and ;; can be combined to any number of levels. ;; can even be used in a way similar to any iterator in Mathematica:

    a[[ start;;end;;step ]]
    

    will do the same things as

    Table[ a[[i]], {i,start,end,step}]
    

    and you can omit one of start, end or step, it is filled with its default of 1, Length[(of the implicit list)], and 1.

    Another thing you might want to lookup in Mathematica’s Help are ReplacePart and MapAt that allow programmatic replacement of structured expressions. The key thing to use this efficiently is that in ReplacePart you can use patterns to specify the coordinates of the things to be replaced, and you can define functions to apply to them.

    Example with your data

    ReplacePart[a, {_, 3} -> 0]
    

    will replace every 3rd part of every sublist with 0.

    ReplacePart[a, {i : _, 3} :> 2*a[[i, 3]]]
    

    will double every 3rd part of every sublist.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is probably a really basic question - but I have a list of
This might be basic question but how do I create a list of lists
I realize this is a basic question but I have searched online, been to
Ok, firstly I have the following code working.. although my question is this; should
Sorry for such a basic question regarding lists, but do we have this feature
I have a basic question regarding assignment of a list of subclass to a
You'll have to forgive me if this is a really basic question; I haven't
I have this basic shopping list app where in the first view there are
This is a basic LINQ question. In my RIA Services Application, I have a
Sorry for this rather basic question, but I have to get some sort of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.