Skip to content

At ​

The element at the given position; a negative index counts from the end.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguagePart!
At(collection, index)the element at index; a negative index counts from the end.
At(collection, [i1, i2, …])the elements at several positions at once.
At(collection, Range(start, end))a contiguous slice selected by a Range.
At(collection, Span(i, j, step))a contiguous (or stepped) slice selected by a Span, negative step included.
At(matrix, rows, columns)the submatrix at the given rows and columns; rows (or columns) as All takes every row (or column).
At(expr, index)a part of ANY expression, not just a collection's — the second term of a sum, say.
Typed signatures
TypePackageApplies
(value: any, index: (boolean | character | indexed_collection<any> | number | string)+) -> unknowncombinatoricsreplaces compute-enginealways
(value: any, index: (boolean | character | indexed_collection<any> | number | string)+) -> unknowncompute-enginealways

Domain: Collections

Details
  • Negative indices count from the end: At(c,−1)At(c, -1) is the last element. See Last.
  • Chaining reaches into nested collections, like indexing a matrix row then column.
  • An out-of-range index evaluates to NaNNaN rather than raising an error.
  • Index 0 is the collection's own head, matching Wolfram's Part[c, 0] — compute-engine gave NaNNaN before.
  • Positional element access, 1-based; negative indices count from the end.
  • Two index lists at the row and column positions extract a submatrix; a SpanSpan takes a contiguous (optionally stepped or reversed) slice.
  • Works on the operands of any expression, not just a collection's — Wolfram's Part reaches into any head.

Examples

11 more kept as data, checked against the oracles
Basic #
live ↗
In[1,2,3,4][2]\bigl\lbrack1, 2, 3, 4\bigr\rbrack[2]Out22
live ↗
In[1,2,3,4][−1]\bigl\lbrack1, 2, 3, 4\bigr\rbrack[-1]Out44
live ↗
In[a,b,c,d][−2]\bigl\lbrack a, b, c, d\bigr\rbrack[-2]Outcc
live ↗
In[a,b,c,d][3]\bigl\lbrack a, b, c, d\bigr\rbrack[3]Outcc
live ↗
In[a,b,c,d,k,f][3]\bigl\lbrack a, b, c, d, k, f\bigr\rbrack[3]Outcc
live ↗
In[a,b,c,d,k,f][−2]\bigl\lbrack a, b, c, d, k, f\bigr\rbrack[-2]Outkk
live ↗
In[a,b,c,d,k,f][Span(2,4)]\bigl\lbrack a, b, c, d, k, f\bigr\rbrack[\mathrm{Span}(2, 4)]Out[b,c,d]\bigl\lbrack b, c, d\bigr\rbrack
Scope #

A list of indices selects several elements at once

live ↗
In[a,b,c,d][[1,3]]\bigl\lbrack a, b, c, d\bigr\rbrack[\bigl\lbrack1, 3\bigr\rbrack]Out[a,c]\bigl\lbrack a, c\bigr\rbrack

A Range also works as an index list, extracting a contiguous slice

live ↗
In[a,b,c,d,e][2..4]\bigl\lbrack a, b, c, d, e\bigr\rbrack[2..4]Out[b,c,d]\bigl\lbrack b, c, d\bigr\rbrack

Index 0 is the collection's own head, matching Wolfram's Part[c, 0]

live ↗
In[1,2,3][0]\bigl\lbrack1, 2, 3\bigr\rbrack[0]OutList\mathrm{List}

Several indices reach into successive levels: row 2, column 3

live ↗
In[[1,2,3],[4,5,6]][2,3]\bigl\lbrack\bigl\lbrack1, 2, 3\bigr\rbrack, \bigl\lbrack4, 5, 6\bigr\rbrack\bigr\rbrack[2, 3]Out66

Negative indices work at every level

live ↗
In[[1,2],[3,4]][−1,−1]\bigl\lbrack\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack3, 4\bigr\rbrack\bigr\rbrack[-1, -1]Out44

Negative indices inside an index list

live ↗
In[a,b,c,d,f][[−1,−2]]\bigl\lbrack a, b, c, d, f\bigr\rbrack[\bigl\lbrack-1, -2\bigr\rbrack]Out[f,d]\bigl\lbrack f, d\bigr\rbrack

A stepped Range takes every other element

live ↗
In[a,b,c,d,f][1..3..5]\bigl\lbrack a, b, c, d, f\bigr\rbrack[1..3..5]Out[a,c,f]\bigl\lbrack a, c, f\bigr\rbrack

Negative bounds count from the end: the last three elements

live ↗
In[a,b,c,d,f][(−3)..(−1)]\bigl\lbrack a, b, c, d, f\bigr\rbrack[(-3)..(-1)]Out[c,d,f]\bigl\lbrack c, d, f\bigr\rbrack

A lazy Range is indexed directly

live ↗
In(5..10)[2](5..10)[2]Out66

AllAll at the first level takes a whole column

live ↗
In[[1,2,3],[4,5,6]][All,2]\bigl\lbrack\bigl\lbrack1, 2, 3\bigr\rbrack, \bigl\lbrack4, 5, 6\bigr\rbrack\bigr\rbrack[\mathrm{All}, 2]Out[2,5]\bigl\lbrack2, 5\bigr\rbrack

Index lists at two levels extract a submatrix (rows 1 and 3, columns 2 and 3)

live ↗
In[[1,2,3],[4,5,6],[7,8,9]][[1,3],[2,3]]\bigl\lbrack\bigl\lbrack1, 2, 3\bigr\rbrack, \bigl\lbrack4, 5, 6\bigr\rbrack, \bigl\lbrack7, 8, 9\bigr\rbrack\bigr\rbrack[\bigl\lbrack1, 3\bigr\rbrack, \bigl\lbrack2, 3\bigr\rbrack]Out[[2,3],[8,9]]\bigl\lbrack\bigl\lbrack2, 3\bigr\rbrack, \bigl\lbrack8, 9\bigr\rbrack\bigr\rbrack

A Span (2;;42;;4 in Wolfram) takes a contiguous slice

live ↗
In[a,b,c,d,f][Span(2,4)]\bigl\lbrack a, b, c, d, f\bigr\rbrack[\mathrm{Span}(2, 4)]Out[b,c,d]\bigl\lbrack b, c, d\bigr\rbrack

A stepped Span (1;;−1;;21;;-1;;2) takes every other element up to the end

live ↗
In[a,b,c,d,f][Span(1,−1,2)]\bigl\lbrack a, b, c, d, f\bigr\rbrack[\mathrm{Span}(1, -1, 2)]Out[a,c,f]\bigl\lbrack a, c, f\bigr\rbrack

A negative step (−1;;1;;−1-1;;1;;-1) walks backwards, reversing the list

live ↗
In[a,b,c,d,f][Span(−1,1,−1)]\bigl\lbrack a, b, c, d, f\bigr\rbrack[\mathrm{Span}(-1, 1, -1)]Out[f,d,c,b,a]\bigl\lbrack f, d, c, b, a\bigr\rbrack

Negative bounds: the last two elements

live ↗
In[a,b,c,d,f][Span(−2,−1)]\bigl\lbrack a, b, c, d, f\bigr\rbrack[\mathrm{Span}(-2, -1)]Out[d,f]\bigl\lbrack d, f\bigr\rbrack

Parts of any expression, not just lists: the second term of a sum

live ↗
In(a+b+c)[2](a+b+c)[2]Outbb

Reaches into a named collection, not just a literal list — here the 5th triangular number, 1-indexed

live ↗
InTriangularNumbers[5]\mathrm{TriangularNumbers}[5]Out1515

Also works on a parameterized collection like PolygonalNumbers(k)PolygonalNumbers(k)

live ↗
InPolygonalNumbers(5)[3]\mathrm{PolygonalNumbers}(5)[3]Out1212
live ↗
InFibonacciNumbers[1]\mathrm{FibonacciNumbers}[1]Out00

At(BellNumbers, 5) is Bell(4) = 15 (1-indexed At, 0-indexed term)

live ↗
InBellNumbers[5]\mathrm{BellNumbers}[5]Out1515

Two indices descend into nested lists

live ↗
In[(x,4),(y,5)][1,2]\bigl\lbrack(x,4), (y,5)\bigr\rbrack[1, 2]Out44
live ↗
In[a,b,c,d,k,f][[1,3,1,2,−1,6]]\bigl\lbrack a, b, c, d, k, f\bigr\rbrack[\bigl\lbrack1, 3, 1, 2, -1, 6\bigr\rbrack]Out[a,c,a,b,f,f]\bigl\lbrack a, c, a, b, f, f\bigr\rbrack
live ↗
In[a,b,c,d,k,f][Span(1,−3)]\bigl\lbrack a, b, c, d, k, f\bigr\rbrack[\mathrm{Span}(1, -3)]Out[a,b,c,d]\bigl\lbrack a, b, c, d\bigr\rbrack
live ↗
In[a,b,c,d,n,f,g,h,m,j,k][Span(3,−3,2)]\bigl\lbrack a, b, c, d, n, f, g, h, m, j, k\bigr\rbrack[\mathrm{Span}(3, -3, 2)]Out[c,n,g,m]\bigl\lbrack c, n, g, m\bigr\rbrack
live ↗
In[[a,b,c],[d,m,f],[g,h,k]][2,3]\bigl\lbrack\bigl\lbrack a, b, c\bigr\rbrack, \bigl\lbrack d, m, f\bigr\rbrack, \bigl\lbrack g, h, k\bigr\rbrack\bigr\rbrack[2, 3]Outff
live ↗
In[[a,b,c],[d,m,f],[g,h,k]][2]\bigl\lbrack\bigl\lbrack a, b, c\bigr\rbrack, \bigl\lbrack d, m, f\bigr\rbrack, \bigl\lbrack g, h, k\bigr\rbrack\bigr\rbrack[2]Out[d,m,f]\bigl\lbrack d, m, f\bigr\rbrack
live ↗
In[[a,b,c],[d,m,f],[g,h,k]][[1,3]]\bigl\lbrack\bigl\lbrack a, b, c\bigr\rbrack, \bigl\lbrack d, m, f\bigr\rbrack, \bigl\lbrack g, h, k\bigr\rbrack\bigr\rbrack[\bigl\lbrack1, 3\bigr\rbrack]Out[[a,b,c],[g,h,k]]\bigl\lbrack\bigl\lbrack a, b, c\bigr\rbrack, \bigl\lbrack g, h, k\bigr\rbrack\bigr\rbrack
live ↗
In[[a,b,c],[d,m,f],[g,h,k]][[1,3],[2,3]]\bigl\lbrack\bigl\lbrack a, b, c\bigr\rbrack, \bigl\lbrack d, m, f\bigr\rbrack, \bigl\lbrack g, h, k\bigr\rbrack\bigr\rbrack[\bigl\lbrack1, 3\bigr\rbrack, \bigl\lbrack2, 3\bigr\rbrack]Out[[b,c],[h,k]]\bigl\lbrack\bigl\lbrack b, c\bigr\rbrack, \bigl\lbrack h, k\bigr\rbrack\bigr\rbrack

One-based indexing

live ↗
In[a,b,c,d,k][3]\bigl\lbrack a, b, c, d, k\bigr\rbrack[3]Outcc

A span selects a contiguous range

live ↗
In[a,b,c,d,k][Span(2,4)]\bigl\lbrack a, b, c, d, k\bigr\rbrack[\mathrm{Span}(2, 4)]Out[b,c,d]\bigl\lbrack b, c, d\bigr\rbrack
Applications #

Chaining AtAt reaches into nested collections, like indexing a matrix row then column

live ↗
In[[1,2],[3,4]][2][1]\bigl\lbrack\bigl\lbrack1, 2\bigr\rbrack, \bigl\lbrack3, 4\bigr\rbrack\bigr\rbrack[2][1]Out33

A list of positions reorders the elements

live ↗
In[a,b,c,d,k][[4,5,1,2,3]]\bigl\lbrack a, b, c, d, k\bigr\rbrack[\bigl\lbrack4, 5, 1, 2, 3\bigr\rbrack]Out[d,k,a,b,c]\bigl\lbrack d, k, a, b, c\bigr\rbrack
Properties #

Index 00 gives the head of the expression

live ↗
In[a,b,c][0]\bigl\lbrack a, b, c\bigr\rbrack[0]OutList\mathrm{List}

An empty list of positions selects nothing

live ↗
In[1,2,3][[]]\bigl\lbrack1, 2, 3\bigr\rbrack[\bigl\lbrack\bigr\rbrack]Out[]\bigl\lbrack\bigr\rbrack
Possible issues #

An out-of-range index evaluates to NaNNaN rather than raising an error

live ↗
In[1,2,3][10]\bigl\lbrack1, 2, 3\bigr\rbrack[10]OutNaN⁡\operatorname{NaN}
About
Examples53
Checked againstWolfram Language 38 agree1 differ
CrosswalkWolfram Language

See also: First, Last, IndexOf, Span