MathGroup Archive 2011

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

Search the Archive

Re: A bug in Partition?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117403] Re: A bug in Partition?
  • From: "Alexey Popkov" <lehin.p at gmail.com>
  • Date: Thu, 17 Mar 2011 06:33:15 -0500 (EST)

Barrie,

Thank you for clear explanation.

My second question is: is there universal way to pad partitioning list at
the start without dropping any elements? I mean the same way as in the case
of padding at the end. The solution I currently use is just a workaround:

list = {a, b, c, d, e, f, g, i};
Reverse /@ Reverse@Partition[Reverse@list, 3, 3, 1, x]

Alexey

----- Original Message ----- 
From: "Barrie Stokes" <Barrie.Stokes at newcastle.edu.au>
To: "Alexey" <lehin.p at gmail.com>; <mathgroup at smc.vnet.net>
Sent: Thursday, March 17, 2011 3:56 AM
Subject: [mg117403] Re: [mg117378] A bug in Partition?


> 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: Expressions as images
  • Next by Date: Re: A bug in Partition?
  • Previous by thread: Re: A bug in Partition?
  • Next by thread: Re: A bug in Partition?