Re: A bug in Partition?
- To: mathgroup at smc.vnet.net
- Subject: [mg117401] Re: A bug in Partition?
- From: Bill Rowe <readnews at sbcglobal.net>
- Date: Thu, 17 Mar 2011 06:32:53 -0500 (EST)
On 3/16/11 at 6:30 AM, lehin.p at gmail.com (Alexey) wrote: >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? Yes, this is the way Partition is supposed to work. By doing Partition[list,n,n,-1,x] you are saying: pad only at the beginning pad using n-1 x with the first element of list in the nth position of the first group take the next set of n elements for the next group continue as long as you can take n more elements stop once you cannot get n elements By doing Partition[list,n,n,1,x] you pad at the end with enough x's to make the flattened length a multiple of n. Perhaps you want to pad at both ends so that nothing gets dropped. If so, do Partition[list,n,n,{-1,1},x] keep in mind Partition[list,n,n,k] is simply shorthand for Partition[list,n,n,{k,k}]