Mathematica 9 is now available

Partition

Usage

Partition[list, n] 划分列表为长度为 n 的非重叠子列表。
Partition[list, n, d] 产生偏移量为 d 的子列表。
Partition[list,   ,  , ...  ] 划分一个嵌套列表为大小为  的块。
Partition[list,   ,  , ...  ,   ,  , ...  ]list 中层i上使用偏移量
Partition[list, n, d,   ,   ] 指定list的第一个元素应当出现在第一个子列表的位置  list的最后一个元素应当出现在最后一个子列表的位置  或其后。如果需要附加元素,Partition通过对待list为循环来填充它们。
• 如果需要,Partition[list, n, d,   ,   , x] 重复元素x来填补。
• 如果需要,Partition[list, n, d,   ,   ,   ,  , ...  ] 通过循环重复元素  填补。
Partition[list, n, d,   ,   ,   ] 不使用任何填补,这样也能产生不同长度的子列表。
Partition[list, nlist, dlist,   ,   , padlist] 指定在一个嵌套列表中的对齐和填补。


Notes

• 例如: Partition[ a,b,c,d,e,f , 2]LongRightArrow .
• 由Partition[list, n, d]产生的所有子列表都有长度 n。在list末尾的一些元素因而可能不出现在任何子列表中。
Partition[ a,b,c,d,e , 2]LongRightArrow 中的元素e被扔掉。
Partition[ a,b,c,d,e , 3, 1]LongRightArrow 产生偏移量为1的子列表。
list中的所有元素出现在由Partition[list, n, 1]产生的子列表中。
• 如果d大于Partition[list, n, d]中的 n,则在list中间的元素被跳过。
Partition[list, 1, d]Take[list,  1, -1, d ]相同的方式挑选元素。
Partition[list, n, d,   ,   ] effectively allows sublists that have overhangs that extend past the beginning or end of list.
Partition[list, n, d,   ,   ] 有效地允许具有超出list的开头或结尾的扩展的子列表。
Partition[list, n, d, k] 等于 Partition[list, n, d,  k, k ].
  ,   的公共选项是:
"\!\(\*StyleBox[\"\\\"{1,\\\"\", \"MR\"]\) \!\(\*StyleBox[\"\\\"-1}\\\"\", \"MR\"]\) "不允许超出
"\!\(\*StyleBox[\"\\\"{1,\\\"\", \"MR\"]\) \!\(\*StyleBox[\"\\\"1}\\\"\", \"MR\"]\) """在结尾允许最大超出
"\!\(\*StyleBox[\"\\\"{-1,\\\"\", \"MR\"]\) \!\(\*StyleBox[\"\\\"-1}\\\"\", \"MR\"]\) "在开头允许最大超出
"\!\(\*StyleBox[\"\\\"{-1,\\\"\", \"MR\"]\) \!\(\*StyleBox[\"\\\"1}\\\"\", \"MR\"]\) "在开头和结尾允许最大超出
• 例如: Partition[ a,b,c,d ,2,1, -1,1 ]LongRightArrow .
Partition[list, n, d,   ,   , padlist] 有效地放置padlist重复拷贝,然后在它们上强加一个list的拷贝,并划分结果。
padlist的公共选项是:
"\!\(\*StyleBox[\"\\\"x\\\"\", \"TI\"]\) "用重复单一元素填补
{"\!\(\*StyleBox[\"\\\"x\\\"\", \"TI\"]\)"1"\!\(\*StyleBox[\"\\\",\\\"\", \"MR\"]\) ""\!\(\*StyleBox[\"\\\"x\\\"\", \"TI\"]\)"2"\!\(\*StyleBox[\"\\\",\\\"\", \"MR\"]\) ... "}" "用循环重复元素序列填补
"\!\(\*StyleBox[\"\\\"list\\\"\", \"TI\"]\) "处理为循环填补缺省
"\!\(\*StyleBox[\"\\\"{}\\\"\", \"MR\"]\) "不填补,潜在的留下不同长度子列表
• 例如: Partition[ a,b,c,d ,2,1, -1,1 , x,y ]LongRightArrow .
Partition[ a,b,c,d ,2,1, -1,1 ,  ]LongRightArrow . • 如果 list 有长度 s, 则Partition[list, n, d] 产生子列表 Max[0, Floor[(s + d - n)/d]] .
Partition[list,   ,  , ... ,   ] 有效地在list中的层r 上用深度为 r 的临近元素的嵌套列表替换元素块。
• 如果没有指定元素块,临域是相邻和不重叠的。
Partition[list,   ,  , ...  , d] 在每层使用偏移量 d .
Partition[list, nlist, dlist,    ,  , ...  ,    ,  , ...   ] 指定list中的元素  1,1,...  应当出现在结果的块  1,1,...  的位置   ,  , ...  ,而list的元素  -1,-1,...  应当出现在结果的块  -1,-1,...  的位置  ,  , ...  或其后。
  ,   取为等于   ,  , ...  ,   ,  , ...   .
   ,  , ...   取为等于   ,  , ...  ,   ,  , ...   .
Partition[list,   ,  , ... ,   , klist, padlist] 有效地构造一个深度为rpadlist拷贝数组,然后在它们上强加一个list的拷贝,并划分结果。
• 如果 list 有维   ,  , ... ,   Partition[list,   ,  , ... ,   ]有维  ,  , ... ,  ,  ,  , ... ,   其中 Floor[ / ]给出. • 对象 list 不必有头 List.
Partition[f[a,b,c,d], 2]LongRightArrow .
• 参见 Mathematica 全书: 1.8.10.
• 同时参见: Flatten, RotateLeft, Split, Take, PadLeft, ListConvolve.
Further Examples

This groups the elements of the original list in pairs; since there is an odd number of elements, the last element is thrown away.

In[1]:=  

Out[1]=

This makes triples of elements, with each successive triple offset by  elements.

In[2]:=  

Out[2]=

Here the offset is  .

In[3]:=  

Out[3]=

This defines a  x  matrix.

In[4]:=  

Out[4]//MatrixForm=

This partitions the matrix into blocks of size  x  . The extra elements that do not fit are thrown away; here these are the last row and last column.

In[5]:=  

Out[5]//MatrixForm=

The  indicates an offset  at level  (the rows) and  at level  (the columns).

In[6]:=  

Out[6]//MatrixForm=

Here the element a appears at position  of the  block and the element y appears at position  of the  block.

In[7]:=  

Out[7]//MatrixForm=

This pads with A, B, C.

In[8]:=  

Out[8]//MatrixForm=

Using Partition to make a cylinder

Here is the direct way to make a cylinder. This loads the package Shapes.

In[9]:=  

Evaluate the cell to see the graphic.

In[10]:=  

Here is another approach using Partition. The function mycylinder[r, h, n] gives the graphic for a cylinder of radius r, height h approximated by n vertical rectangles.

In[11]:=  

Evaluate the cell to see the graphic.

In[12]:=  

In[13]:=  



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.