Accidental Nested Arrays?

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...
Post Reply
conor_f
Posts: 13
Joined: Wed May 29, 2013 7:33 pm

Accidental Nested Arrays?

Post by conor_f »

Take the example:

Code: Select all

      ones ← 2 2⍴ 1

      twos ← 2 2⍴2

      togethers ← ones twos

      togethers
┌→──┬───┐
│1 1│2 2│
│1 1↓2 2↓
└~─→┴~─→┘

⍝All as expected so far, but then...
    togethers ← togethers ones

    togethers
┌→────────┬───┐
│┌→──┬───┐│1 1│
││1 1│2 2││1 1│
││1 1↓2 2↓│   │
│└~─→┴~─→┘│   ↓
└────────→┴~─→┘


Which doesn't make any sense to me.... I was expecting a similar vector as from the first display output, instead I get a nested vector... What is the correct way to structure this to get the output I want? (i.e. a vector containing three elements just like what I'd have if I ran togethers ← ones twos ones)

(Sorry for yet another question... I am searching and researching all the resources I have/can find...)
JohnS|Dyalog

Re: Accidental Nested Arrays?

Post by JohnS|Dyalog »

Hi Conor,
The juxtaposition of two arrays produces a 2-item vector, which is what you got with the two arrays: together ones.
I wonder if the following sequence helps:

Code: Select all

      ones twos threes fours ← 2 2∘⍴¨⍳4
      ones twos
┌→──┬───┐
│1 1│2 2│
│1 1↓2 2↓
└~─→┴~─→┘
      ones twos threes
┌→──┬───┬───┐
│1 1│2 2│3 3│
│1 1↓2 2↓3 3↓
└~─→┴~─→┴~─→┘
      ⎕ ← togethers ← ones twos
┌→──┬───┐
│1 1│2 2│
│1 1↓2 2↓
└~─→┴~─→┘
     
      others ← threes fours

      togethers others
┌→────────┬─────────┐
│┌→──┬───┐│┌→──┬───┐│
││1 1│2 2│││3 3│4 4││
││1 1↓2 2↓││3 3↓4 4↓│
│└~─→┴~─→┘│└~─→┴~─→┘│
└────────→┴────────→┘
      togethers , others  ⍝ concatenating 2 items with 2 items (note the comma).
┌→──┬───┬───┬───┐
│1 1│2 2│3 3│4 4│
│1 1↓2 2↓3 3↓4 4↓
└~─→┴~─→┴~─→┴~─→┘
      togethers , ⊂threes  ⍝ concatenating 2 items with 1 item.
┌→──┬───┬───┐
│1 1│2 2│3 3│
│1 1↓2 2↓3 3↓
└~─→┴~─→┴~─→┘
conor_f
Posts: 13
Joined: Wed May 29, 2013 7:33 pm

Re: Accidental Nested Arrays?

Post by conor_f »

Hi John,
This is perfect. Thank you. I suspected the enclose function was needed, but I wasn't sure how. :)
Post Reply