WOLFRAM

Take[list,n]

gives the first n elements of list.

Take[list,-n]

gives the last n elements of list.

Take[list,{m,n}]

gives elements m through n of list.

Take[list,seq1,seq2,]

gives a nested list in which elements specified by seqi are taken at level i in list.

Details

  • Take uses the standard sequence specification:
  • Allall elements
    Noneno elements
    nelements 1 through n
    UpTo[n]elements 1 up to at most n, as available
    -nlast n elements
    {n}element n only
    {m,n}elements m through n inclusive
    {m,n,s}elements m through n in steps of s
  • Take can be used on an object with any head, not necessarily List.
  • Take[list,seq1,seq2] effectively extracts a submatrix from list.
  • Applying Take to a SparseArray object normally yields another SparseArray object.
  • Applying Take to an Association object yields an Association containing elements from the specified positions.

Examples

open allclose all

Basic Examples  (6)Summary of the most common use cases

Take the first 4 elements from a list:

Out[1]=1

Take the last 3 elements:

Out[1]=1

Take elements 2 through 4:

Out[1]=1

Take the second element from an Association:

Out[1]=1

Take all but the first element from an Association:

Out[1]=1

Take every other element from 2 to 6 from an Association:

Out[1]=1

Scope  (8)Survey of the scope of standard use cases

Take elements from the second to the second-to-last:

Out[1]=1

Take every other element:

Out[1]=1

Take the first two rows of a matrix:

Out[1]=1

Take all rows, and the first two columns:

Out[1]=1

Take the first two rows, and the last column:

Out[1]=1

Take a submatrix:

Take every other row and column:

Take the first 4 elements if possible, else as many as are available:

Out[1]=1

Generalizations & Extensions  (2)Generalized and extended use cases

Take works with any head, not just List:

Out[1]=1
Out[2]=2
Out[3]=3

Take works with SparseArray objects:

Out[1]=1
Out[2]=2

Applications  (2)Sample problems that can be solved with this function

Pick out a subimage:

Out[1]=1
Out[2]=2

Sample every third cell in an image:

Out[1]=1
Out[2]=2

Properties & Relations  (5)Properties of the function, and connections to other functions

Take and Drop are complementary:

Out[1]=1
Out[2]=2

Take is often equivalent to Part extraction with Range:

Out[1]=1
Out[2]=2
Out[3]=3
Out[4]=4

Take is equivalent to Part extraction with Span:

Out[1]=1
Out[2]=2
Out[3]=3

Take gives an array whose first dimensions are its arguments:

Out[1]=1

Reverse[e] is equivalent to Take[e,{-1,1,-1}]:

Out[1]=1
Out[2]=2
Out[3]=3

Possible Issues  (1)Common pitfalls and unexpected behavior

Take always returns a list, even if it is just taking a single element:

Out[1]=1
Wolfram Research (1988), Take, Wolfram Language function, https://reference.wolfram.com/language/ref/Take.html (updated 2015).
Wolfram Research (1988), Take, Wolfram Language function, https://reference.wolfram.com/language/ref/Take.html (updated 2015).

Text

Wolfram Research (1988), Take, Wolfram Language function, https://reference.wolfram.com/language/ref/Take.html (updated 2015).

Wolfram Research (1988), Take, Wolfram Language function, https://reference.wolfram.com/language/ref/Take.html (updated 2015).

CMS

Wolfram Language. 1988. "Take." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/Take.html.

Wolfram Language. 1988. "Take." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/Take.html.

APA

Wolfram Language. (1988). Take. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Take.html

Wolfram Language. (1988). Take. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Take.html

BibTeX

@misc{reference.wolfram_2025_take, author="Wolfram Research", title="{Take}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/Take.html}", note=[Accessed: 21-April-2025 ]}

@misc{reference.wolfram_2025_take, author="Wolfram Research", title="{Take}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/Take.html}", note=[Accessed: 21-April-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_take, organization={Wolfram Research}, title={Take}, year={2015}, url={https://reference.wolfram.com/language/ref/Take.html}, note=[Accessed: 21-April-2025 ]}

@online{reference.wolfram_2025_take, organization={Wolfram Research}, title={Take}, year={2015}, url={https://reference.wolfram.com/language/ref/Take.html}, note=[Accessed: 21-April-2025 ]}