## ⍳/ ? What does it do ?

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

### ⍳/ ? What does it do ?

on page 380 of the book : "Mastering Dyalog APL" it shows

⍳/ (2 6 1 7) (2 4⍴3 7 8 4 2 5 6 0)

Resulting in :
5 4 5 5
1 5 2 5

Please explain what ⍳/ does. Thanks.
hbarkhof

Posts: 44
Joined: Mon Apr 09, 2018 8:37 am

### Re: ⍳/ ? What does it do ?

The general definition of / is to put the function to its left between all items to its right.

Therefore +/1 2 3 becomes 1+2+3.

Accordingly ⍳/ (2 6 1 7) (2 4⍴3 7 8 4 2 5 6 0) becomes
2 6 1 7 ⍳ 2 4⍴3 7 8 4 2 5 6 0

That's all.

Because the concept is so general you can use the / (scan) operator with any conforming function:

`      ∨/ 0 0 0 1 0 01      -/ 0 2 3 ¯9 0 010      ≡/'APL' 'COBOL'0      ≡/'APL' 'APL'1`

kai

Posts: 115
Joined: Thu Jun 18, 2009 5:10 pm
Location: Stevenage, UK

### Re: ⍳/ ? What does it do ?

Thanks Kai.

Unfortunally I don't see how (2 6 1 7) ⍳ 2 4⍴3 7 8 4 2 5 6 0
gives as result 5455 1525 ???

I do know that 2 4⍴3 7 8 4 2 5 6 0 gives
3784
2560
That is the easy part :) But with (2 6 1 7)⍳ in front of it ??
hbarkhof

Posts: 44
Joined: Mon Apr 09, 2018 8:37 am

### Re: ⍳/ ? What does it do ?

I do know that 2 4⍴3 7 8 4 2 5 6 0 gives
3784
2560

You mean

3 7 8 4
2 5 6 0

rather than

3784
2560

I hope.

The fact that the right argument is a matrix rather than a vector can be ignored:

2 6 1 7 ⍳ 3 7 8 4 2 5 6 0

gives exactly the same result but in a different shape.

To phrase it differently: the fact that the right argument is a matrix has no impact whatsoever on how ⍳ works, it just defines the shape of the result.

That is another concept in APL you need to internalize. Study these examples:

Code: Select all
`      (1 2 3)[2 3 1]2 3 1      (1 2 3)[2 3 4⍴2 3 1]2 3 1 23 1 2 31 2 3 1       2 3 1 23 1 2 31 2 3 1`

The shape of the argument (=what's inside []) has no influence on how indexing works, but it defines the shape of the result.

If it's still unclear keep asking.

kai

Posts: 115
Joined: Thu Jun 18, 2009 5:10 pm
Location: Stevenage, UK

### Re: ⍳/ ? What does it do ?

Code: Select all
`    (2 6 1 7) ⍳ 2 4⍴3 7 8 4 2 5 6 05 4 5 51 5 2 5`

The result has the same shape and rank as the right hand argument, so it is 2 rows by 4 columns.

In the top row the results are
Code: Select all
`      2 6 1 7⍳35      2 6 1 7⍳74      2 6 1 7⍳85      2 6 1 7⍳45`

and the bottom row are
Code: Select all
`     2 6 1 7⍳21     2 6 1 7⍳55     2 6 1 7⍳62     2 6 1 7⍳05`

Where do all the "5"s come from?
R←X⍳Y
"If an element of Y cannot be found in X, then the corresponding element of R will be ⎕IO+⊃⍴X."
All the "5" correspond with items in Y which are not in X, and since X is 4 items long, (in ⎕IO 1) these results will be 1+4←→5

In ⎕IO 0
Code: Select all
`         ⎕IO←0       (2 6 1 7) ⍳ 2 4⍴3 7 8 4 2 5 6 04 3 4 40 4 1 4`

I hope this is making sense.
Ray Cannon

ray

Posts: 173
Joined: Wed Feb 24, 2010 12:24 am
Location: Blackwater, Camberley. UK

### Re: ⍳/ ? What does it do ?

ray wrote:The result has the same shape and rank as the right hand argument, so it is 2 rows by 4 columns.

This was true until dyadic iota was extended to left arguments of higher rank. Today, it is more correct to say that the search is for "major cells" of the left argument (sub-arrays of rank 1 less than the argument).

For example:
Code: Select all
`      ⎕←mat←3 4⍴⍳121  2  3  45  6  7  89 10 11 12      ⍴⎕←mat⍳⊖mat ⍝look for rows of reverse of mat in self, return 3-element vector3 2 13      ⍴⍴⎕←mat⍳5 6 7 8 ⍝ look for vector in mat, return scalar result20`

Rather than simply being of shape (⍴⍵), the result has the shape:

Code: Select all
`(1-⍴⍴⍺)↓⍴⍵`

For a vector left argument, the search is for scalars and (1-⍴⍴⍺) is 0.

Morten|Dyalog

Posts: 392
Joined: Tue Sep 09, 2008 3:52 pm

### Re: ⍳/ ? What does it do ?

Now it is very clear to me. Thank you all !
Sorry for "Silly" question :)
More will follow , I'm afraid.
hbarkhof

Posts: 44
Joined: Mon Apr 09, 2018 8:37 am

### Re: ⍳/ ? What does it do ?

> Sorry for "Silly" question :)

We've all gone through this although you might come across some jerk every now and then who seems to have forgotten.

"If you ask a question it might make you look stupid for a couple of minutes, but if you don't ask you stay stupid, so you better keep asking."

kai

Posts: 115
Joined: Thu Jun 18, 2009 5:10 pm
Location: Stevenage, UK