Pick with Zilde as an argument
3 posts
• Page 1 of 1
Pick with Zilde as an argument
Hi all,
While studying "APL 2 At A Glance" I've encountered the following exercise which I couldn't understand.
Given vector
I'm trying to understand the following statement:
While the code
produces the error.
From what I can understand 3 should give us the 3rd element of the vector, which is enclosed array 'XYZ'. So the error in second case is understandable  we can't get the value from the scalar.
Why then the ⍳0 in the middle could help?
Running it separately:
so it is not removing the scalar enclosure.
While studying "APL 2 At A Glance" I've encountered the following exercise which I couldn't understand.
Given vector
 Code: Select all
A←(⍳4)(2 3⍴'ABCDEF')(⊂'XYZ')(6 (7 8))
I'm trying to understand the following statement:
 Code: Select all
3(⍳0)2⊃A
Y
While the code
 Code: Select all
3 2⊃A
RANK ERROR
produces the error.
From what I can understand 3 should give us the 3rd element of the vector, which is enclosed array 'XYZ'. So the error in second case is understandable  we can't get the value from the scalar.
Why then the ⍳0 in the middle could help?
Running it separately:
 Code: Select all
(⍳0)⊃3⊃A
┌───────┐
│ ┌→──┐ │
│ │XYZ│ │
│ └───┘ │
└∊──────┘
so it is not removing the scalar enclosure.
 alexeyv
 Posts: 50
 Joined: Tue Nov 17, 2015 4:18 pm
Re: Pick with Zilde as an argument
The left argument of pick is a vector, which defines a "path" through the (typically nested) right argument array.
Each item in the path is a vector, whose shape matches the rank of the right argument item into which we're picking: a 2vector item picks into a matrix; a 1vector item picks into a vector and a 0vector item picks into a scalar.
Pick is permissive on two counts:
 A scalar path is interpreted as a 1vector path
 A scalar pathitem is interpreted as a 1vector pathitem
so:
Note that an empty (0vector) path does zero picking, while a path with one empty (0vector) item picks into a scalar:
User command ]display is our friend when playing with pick. Each item in the path penetrates one border:
Each item in the path is a vector, whose shape matches the rank of the right argument item into which we're picking: a 2vector item picks into a matrix; a 1vector item picks into a vector and a 0vector item picks into a scalar.
Pick is permissive on two counts:
 A scalar path is interpreted as a 1vector path
 A scalar pathitem is interpreted as a 1vector pathitem
so:
2⊃'hello' 'world' ⍝ A scalar path is interpreted as
world
(,2)⊃'hello' 'world' ⍝ a 1vector path with a scalar item, which is
world
(,⊂,2)⊃'hello' 'world' ⍝ interpreted as a 1vector item.
world
Note that an empty (0vector) path does zero picking, while a path with one empty (0vector) item picks into a scalar:
s ← ⊂'xyz' ⍝ s is scalar
s ≡ (⍳0)⊃s ⍝ (⍳0) is a 0path
1
'xyz' ≡ (⊂⍳0)⊃s ⍝ (⊂⍳0) a 1path with one 0item
1
User command ]display is our friend when playing with pick. Each item in the path penetrates one border:
]display hello ← ⊂⊂1 1⍴⊂⊂'hello'
┌─────────────────────┐
│ ┌─────────────────┐ │
│ │ ┌→────────────┐ │ │
│ │ ↓ ┌─────────┐ │ │ │
│ │ │ │ ┌→────┐ │ │ │ │
│ │ │ │ │hello│ │ │ │ │
│ │ │ │ └─────┘ │ │ │ │
│ │ │ └∊────────┘ │ │ │
│ │ └∊────────────┘ │ │
│ └∊────────────────┘ │
└∊────────────────────┘
]display ⍬ ⍬ ⊃ hello
┌→────────────┐
↓ ┌─────────┐ │
│ │ ┌→────┐ │ │
│ │ │hello│ │ │
│ │ └─────┘ │ │
│ └∊────────┘ │
└∊────────────┘
]display ⍬ ⍬(1 1) ⊃ hello
┌─────────┐
│ ┌→────┐ │
│ │hello│ │
│ └─────┘ │
└∊────────┘
]display ⍬ ⍬(1 1)⍬ ⊃ hello
┌→────┐
│hello│
└─────┘
]display ⍬ ⍬(1 1)⍬ 2 ⊃ hello
e


JohnSDyalog  Posts: 158
 Joined: Wed Sep 10, 2008 10:01 am
Re: Pick with Zilde as an argument
Thanks for the detailed explanations! I guess the
is the actual answer to my question. Now it is more clear.
a 2vector item picks into a matrix; a 1vector item picks into a vector and a 0vector item picks into a scalar.
is the actual answer to my question. Now it is more clear.
 alexeyv
 Posts: 50
 Joined: Tue Nov 17, 2015 4:18 pm
3 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group