Extract

Extract[expr, list]
extracts the part of expr at the position specified by list.

Extract[expr, {list1, list2, ...}]
extracts a list of parts of expr.

Extract[expr, list, h]
extracts parts of expr, wrapping each of them with head h before evaluation.

DetailsDetails

  • Extract[expr, {i, j, ...}] is equivalent to Part[expr, i, j, ...].
  • The position specifications used by Extract have the same form as those returned by Position, and used in functions such as MapAt and ReplacePart.
  • You can use Extract[expr, ..., Hold] to extract parts without evaluation.
  • If expr is a SparseArray object, Extract[expr, ...] extracts parts in the corresponding ordinary array.

ExamplesExamplesopen allclose all

Basic Examples (3)Basic Examples (3)

Extract the second part from an expression:

In[1]:=
Click for copyable input
Out[1]=

Extract a part nested in an expression:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=

Extract parts from multiple positions:

In[3]:=
Click for copyable input
Out[3]=

Extract the parts given by Position:

In[1]:=
Click for copyable input
In[2]:=
Click for copyable input
Out[2]=
In[3]:=
Click for copyable input
Out[3]=
New in 3 | Last modified in 5
New to Mathematica? Find your learning path »
Have a question? Ask support »