MathGroup Archive 2011

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

Search the Archive

Re: A bug in Partition?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg117387] Re: A bug in Partition?
  • From: Bob Hanlon <hanlonr at cox.net>
  • Date: Thu, 17 Mar 2011 06:30:18 -0500 (EST)

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

{{x, x, a}, {b, c, d}, {e, f, g}}

The documentation shows that position 4 should be a two-element list. So the -1 is taken to mean {-1, -1}

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

{{x, x, a}, {b, c, d}, {e, f, g}}

The padding can only go to the outside (start of the first list or end of the last list). Putting i in the last ( -1 ) position of the last list would require padding inside, so i is discarded.  i must be in the first position of the last list. Use either

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

{{x, x, a}, {b, c, d}, {e, f, g}, {i, x, x}}

or

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

{{x, x, a}, {b, c, d}, {e, f, g}, {i, x, x}}


Whereas

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

{{a, b, c}, {d, e, f}, {g, i, x}}

The 1 is taken to mean {1, 1} and pads to the outside.

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

{{a, b, c}, {d, e, f}, {g, i, x}}


Bob Hanlon

---- 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: Joining points of ListPlot
  • Next by Date: Re: mathematica fit data to inverse gamma distribution
  • Previous by thread: Re: A bug in Partition?
  • Next by thread: Re: A bug in Partition?