MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: A bug in Partition?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117397] Re: A bug in Partition?
  • From: Barrie Stokes <Barrie.Stokes at newcastle.edu.au>
  • Date: Thu, 17 Mar 2011 06:32:08 -0500 (EST)

Hi Alexey

The documentation (Version 8) for Partition says, in part:
"Partition[list,n,d,{Subscript[k, L],Subscript[k, R]}] specifies that the first element of list should appear at position Subscript[k, L] in the first sublist, and the last element of list should appear at or after position Subscript[k, R] in the last sublist. If additional elements are needed, Partition fills them in by treating list as cyclic. Partition[list,n,d,{Subscript[k, L],Subscript[k, R]},x] pads if necessary by repeating the element x."

In your second line, Partition[{a,b,c,d,e,f,g,i},3,3,1,x], we thus should see that the first element of list should appear at position 1 in the first sublist, with padding by repeating the element x to complete the construction of three sublists of three elements. This is what we get.

In[183]:= Partition[{a, b, c, d, e, f, g, i}, 3, 3, 1, x]

Out[183]= {{a, b, c}, {d, e, f}, {g, i, x}}

In your first line, then, Partition[{a,b,c,d,e,f,g,i},3,3,-1,x], we thus should see that the first element of list should appear at position -1 in the first sublist. Since this mean at the end of the first sublist, the padding at the start requires two x's. The remaining "unused" elements in list are now (more than!) sufficient to complete the construction of three sublists of three elements. The "i" element is not needed. This is indeed what we get.

In[184]:= Partition[{a, b, c, d, e, f, g, i}, 3, 3, -1, x]

Out[184]= {{x, x, a}, {b, c, d}, {e, f, g}}

I think Partition is doing what it promises.

Cheers

Barrie

>>> On 16/03/2011 at 10:30 pm, in message <201103161130.GAA12004 at smc.vnet.net>,
Alexey <lehin.p at gmail.com> wrote:
> Hello,
> 
> Consider the following:
> 
> In[3]:=
> Partition[{a,b,c,d,e,f,g,i},3,3,-1,x]
> Partition[{a,b,c,d,e,f,g,i},3,3,1,x]
> Out[3]=
> {{x,x,a},{b,c,d},{e,f,g}}
> Out[4]=
> {{a,b,c},{d,e,f},{g,i,x}}
> 
> One can see that in the first case element 'i' is dropped! Why this
> happens? Is this intended behavior?




  • Prev by Date: Re: A bug in Partition?
  • Next by Date: Re: Joining points of ListPlot
  • Previous by thread: Re: A bug in Partition?
  • Next by thread: Re: A bug in Partition?