此为 Mathematica 7 文档,内容基于更早版本的 Wolfram 语言
查看最新文档(版本11.2)
Mathematica HowTo
How to | Get Elements of Lists
Lists are very important structures in Mathematica. Lists allow you treat any kind of collection of objects as a single entity. Sometimes you need to pick out or extract individual elements or groups of elements from a list.
Set up a list of the first 10 squares (stored as v):
In[1]:=
Click for copyable input
Out[1]=
Use Part to pick the third element of the list:
In[2]:=
Click for copyable input
Out[2]=
Or use [[...]] (the short form notation for Part):
In[3]:=
Click for copyable input
Out[3]=
Combine ;; (the short form for Span) with Part to pick out the elements from 1 to 5:
In[4]:=
Click for copyable input
Out[4]=
Pick out elements 5 through 8 of the list:
In[5]:=
Click for copyable input
Out[5]=
Pick the last 7 elements (negative indices count from the end):
In[6]:=
Click for copyable input
Out[6]=
    
A matrix in Mathematica is a list of lists of the same length. You can pick out elements from a matrix just like you would from a list.
Set up a 5×5 matrix of integers:
In[7]:=
Click for copyable input
Out[7]=
Use MatrixForm to see it laid out as a matrix:
In[8]:=
Click for copyable input
Out[8]//MatrixForm=
The first part of the matrix is the first row:
In[9]:=
Click for copyable input
Out[9]=