>>
APLDN Home

>>
Events

>>
Trainings

>>
APL Books

>>
APLDN Links

>>
Discussion Groups

>>
Downloads

>>
Articles

>>
Library

>>
Learning Tools

>>
APLDN User IO

>>
APL2000.com




General

Author Thread: Choose Indexing!
davin.church
Choose Indexing!
Posted: Tuesday, December 19, 2006 8:48 PM (EST)

I just found something that I'm amazed that I didn't know about (or perhaps just didn't remember).  APL+Win supports Choose Indexing, at least as far back as v3.0!

 

Choose Indexing is a method of using a nested array as a subscript to select (scatter-point) items from an array without using semicolons.  For instance:

 

      a„3 4½¼12
      a
 1  2  3  4
 5  6  7  8
 9 10 11 12
      a[(1 2) (3 4)] © Choose indexing
2 12

 

Did anyone else already know about this?  Why isn't it documented -- is it considered unreliable or unsupported in some way?


Comments:

Author Thread:
brent.hildebrand
Choose Indexing!
Posted: Wednesday, December 20, 2006 8:14 AM (EST)

 

I've used this.  What is nice is to build a nested array to use to choose items. 

 

      a„3 4½¼12
      a[(1 2) (3 4)]
2 12
      a[(1 1)(2 2)]
1 6
      b„(1 1)(2 2)
      a[b]
1 6
 

     

davin.church
Choose Indexing!
Posted: Wednesday, December 20, 2006 1:23 PM (EST)

How did you know it was there?  Did I miss it in the documentation?

     

brent.hildebrand
Choose Indexing!
Posted: Wednesday, December 20, 2006 4:03 PM (EST)

I can't tell you when I learn this.  I've just used if for quite some time.  But a quick look at the user documentation yields this on page 80 of APL+Win   User Manual which list indexarray as an option for Brackes [ ]:

 

Brackets   []
Use: Index into
Syntax: res „arg[idx1;idx2; ... ]
  res „arg[indexarray]
Description:
Select a subset of elements from an array.
arg:  any nonscalar array.
index:  the index can be either of two forms: a list of simple arrays (idxn) separated by semicolons, or a nested array of enclosed vectors (indexarray).
If the index is a list of simple arrays, it must have the same number of arrays as arg has dimensions; you separate the items with semicolons.  Each idx value corresponds to one dimension of arg.  An idx value can be an integer array of any shape; its elements specify the values of the dimension you want to select.  The elements of idx cannot exceed the length of arg for that dimension.  You can leave an index blank, using only the semicolon; in this case, you specify the entire dimension.  When the index has the form idx1;...idxn, res is the portion of arg specified by the index arrays.  The number of elements in the idx items determine the shape of arg.  See the Introduction to the Language chapter in this manual for more examples of this form of indexing.
If the index is an array of enclosed vectors, indexarray can have any shape, but each item of indexarray must be a simple vector of length n, where n is ½½arg.  Each item specifies one point in arg; each element of the simple vector specifies the value of the dimension that represents the point.  (For example, if arg is a three-dimensional matrix, an item of indexarray would have three scalars, representing the plane, row and column of the point desired.) 
When the index has the form indexarray, res is an array whose shape is identical to the shape of indexarray, and whose values represent the points specified.
ext:  Œio.
Example:
      3 4 7 3 8 [3 2 1]
7 4 3
      'ABCD'[3 2]
CB
      (3 4½¼12)[;3]
3 7 11
      'ABC'[4 4½¼3]
ABCA
BCAB
CABC
ABCA
      (3 4½¼12)[(1 1)(2 2)(3 3)]
1 6 11

     

Support
Choose Indexing!
Posted: Wednesday, December 20, 2006 5:11 PM (EST)

Davin: Choose Indexing was introduced in APL*PLUS II/386 and has been in APL+Win since version 1.

 

APL2000 Support

     



APL2000 Official Web Site

I don't pretend to understand the Universe - it's a great deal bigger than I am.
-- Thomas Carlyle

APLDN Home   |    |  Events   |  Trainings   |  APL Books   |  APLDN Links   |    |  Discussion Groups   |    |  Downloads   |  Articles   |  Library   |  Learning Tools   |  APLDN User IO   |  APL2000.com   |