bug-apl
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Bug-apl] Index function returns extra elements.


From: Hans-Peter Sorge
Subject: Re: [Bug-apl] Index function returns extra elements.
Date: Tue, 6 Nov 2018 18:08:31 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.2.1

Hi Jay,

My intend was to get each matrix element defined by a (row,column)-pair
like:

      1 3 5∘.,1 3 5 ⍝ the row,column pairs in a matrix
 1 1  1 3  1 5
 3 1  3 3  3 5
 5 1  5 3  5 5

      (1 3 5∘.,1 3 5)⌷¨⊂A ⍝ the matrix elements (in a matrix)
ACE
KMO
UWY

      (1 3 ∘.,1 3 )⌷¨⊂A  ⍝ works nicely too - just two elements per vector
AC
KM

      (1 3) (1 3) ⌷¨⊂A  ⍝ This works too, having just a vector of
vectors - no matrix
CC
      (1 3) (1 5) ⌷¨⊂A  ⍝ Again - works - different elements from one
row but ..
CE
      (1 3) (5 1) ⌷¨⊂A  ⍝ .. but the elements should be from different rows
CU

      (2 1⍴(1 3) (5 1)) ⌷¨⊂A ⍝ And even better, getting the elements in
row order too - this was, what I intended.
C
U

      (1 3) (5 1) ⌷A    ⍝ However I got this - not realizing straight
away I was on an other indexing trip:-)
EA
OK

Can you imagine what happens at 24:00 hours when you get a matrix
instead of a vector not including the

elements (CU) you are looking for??

Best Regards

Hans-Peter



Am 06.11.18 um 15:42 schrieb Jay Foad:
>       ⎕←t←5 5⍴⎕A
> ABCDE
> FGHIJ
> KLMNO
> PQRST
> UVWXY
>       (1 3 5)(1 3 5)⌷t               
> ACE
> KMO
> UWY
>       t[1 3 5;1 3 5]≡(1 3 5)(1 3 5)⌷t
> 1
>  
> Perhaps you wanted to use something like Dyalog's choose indexing?
>
>       x[(∊2=⍴¨x)/,s]
> ┌──┬──┐
> │XX│XX│
> └──┴──┘
>
> Jay.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]