## Partitionning a vector question

For users of dfns, both novice and expert

### Partitionning a vector question

Hello everyone, I am trying to partition an even vector as follow:

`      {↓(((0.5×⍴⍵),2)⍴⍵)}⍳10 1 2  3 4  5 6  7 8  9 10`

is someone has a more 'elegant' solution than going through a matrix for doing that.

PGilbert

Posts: 401
Joined: Sun Dec 13, 2009 8:46 pm

### Re: Partitionning a vector question

`      x⊂⍨1 0⍴⍨≢x`

I don't know whether you'd consider it more "elegant". It IS shorter. It's not quite as fast as ↓ of a 2-column matrix because ↓ can exploit the regularity that is not practically detectable by ⊂.
Roger|Dyalog

Posts: 215
Joined: Thu Jul 28, 2011 10:53 am

### Re: Partitionning a vector question

Hello Roger, I am not obtaining the expected result for ⍳10:
`      {⍵⊂⍨1 0⍴⍨≢⍵}⍳10 1  3  5  7  9`

PGilbert

Posts: 401
Joined: Sun Dec 13, 2009 8:46 pm

### Re: Partitionning a vector question

The expression requires ⎕ml≤2.
Roger|Dyalog

Posts: 215
Joined: Thu Jul 28, 2011 10:53 am

### Re: Partitionning a vector question

Thanks its working with ⎕ml←2 (I was ⎕ml←3)

PGilbert

Posts: 401
Joined: Sun Dec 13, 2009 8:46 pm

### Re: Partitionning a vector question

Hi,
Roger's solution may be made slightly shorter by
x⊂⍨2|⍳≢x
but this means that (⎕ML ⎕IO)←0 1
(and I'm quite sure that Roger won't use 1 for index origin..)

Tricks aside, you may use either Dyalog partition
{((≢⍵)⍴1 0)⊂⍵⊣⎕ML←2}
or APL2 style
{((≢⍵)⍴2 1)⊂⍵⊣⎕ML←3}

-wm
Veli-Matti

Posts: 56
Joined: Sat Nov 28, 2009 3:12 pm

### Re: Partitionning a vector question

Thanks Veli-Matti and Roger, I learned a little bit more about partition today and the interaction of ⎕ML. Since we are using ⎕ML←3, the expression {((⍴⍵)⍴2 1)⊂⍵} is what I was looking for.

PGilbert

Posts: 401
Joined: Sun Dec 13, 2009 8:46 pm

### Who is online

Users browsing this forum: No registered users and 0 guests