Indices: Difference between revisions

Jump to navigation Jump to search
1,591 bytes added ,  03:08, 6 December 2019
no edit summary
m (20 revisions imported: Migrate from miraheze)
No edit summary
Line 1: Line 1:
:''This page describes a primitive whose result is a list of indices. See [[Index]] for the page on indices themselves. See [[Index of]] for the index generator.''
:''This page describes a primitive whose result is a list of indices. See [[Index]] for the page on indices themselves. See [[Index of]] for the index generator.''


{{Built-in|Indices|⍸}} or '''Where''', is a [[monadic]] [[primitive function]] which returns the [[Index|indices]] of all ones in a [[Boolean]] array. More generally, Indices accepts an array of non-negative integers and copies each index the corresponding number of times.
{{Built-in|Indices|⍸}}, or '''Where''', is a [[monadic]] [[primitive function]] which returns the [[Index|indices]] of all ones in a [[Boolean]] array. More generally, Indices accepts an array of non-negative integers and copies each index the corresponding number of times.


Indices was introduced in [[J]] as <source lang=j inline>I.</source> and is present in [[K]] as <source lang=k inline>&</source>.
Where on a Boolean argument was introduced in [[K]] as <source lang=k inline>&</source>, and it was extended to non-negative integers in [[J]], with the name Indices (<source lang=j inline>I.</source>).


== Examples ==
== Examples ==
Line 51: Line 51:


Indices may be viewed as a way to convert between two ways of writing [[wikipedia:multiset|multiset]]s of array [[Index|indices]]. The argument uses a dense representation indicating for each index the number of times it appears, and the result uses a sparse representation which lists all the indices contained in the set.
Indices may be viewed as a way to convert between two ways of writing [[wikipedia:multiset|multiset]]s of array [[Index|indices]]. The argument uses a dense representation indicating for each index the number of times it appears, and the result uses a sparse representation which lists all the indices contained in the set.
== History ==
[[Idiom]]s with similar behavior to Indices were widely used in APL long before it was made into a primitive. For example, the [[FinnAPL idiom library]], first presented in 1984, lists <source lang=apl inline>X/⍳⍴X</source> as "594. Indices of ones in logical vector X".
Where (<source lang=k inline>&</source>) with a Boolean argument was present in [[K]] by K2 in 1998.<ref>Kx Systems. [http://web.archive.org/web/20041022042401/http://www.kx.com/technical/documents/kusrlite.pdf "K User Manual"]. 1998.</ref> It was extended to vectors of non-negative integers when it was added to [[J]] as Indices (<source lang=j inline>I.</source>) in release 5.02 (2003).<ref>Jsoftware. [https://www.jsoftware.com/docs/archive/release/ifb.htm "I. Implements ''Indices'']. 2003.</ref>
Indices (<source lang=j inline>⍸</source>) was first introduced to APL, and the [[nested array model]], by [[NARS2000]]. Originally defined only for vectors, the current definition <source lang=apl inline>(,R)/,⍳⍴1/R</source> was introduced in about 2013 after some experimentation with other definitions.<ref>NARS2000 Wiki. [http://wiki.nars2000.org/index.php?title=Indices&direction=next&oldid=863 Indices]. Old revision: 2013-05-26.</ref> Where (<source lang=j inline>⍸</source>) with the same definition was added to [[Dyalog APL 16.0]] with the restriction that the argument be Boolean, and this restriction was lifted to allow non-negative integers in [[Dyalog APL 18.0]].


== Documentation ==
== Documentation ==
Line 63: Line 71:


[https://chat.stackexchange.com/transcript/52405?m=41724812#41724812 APL Cultivation]
[https://chat.stackexchange.com/transcript/52405?m=41724812#41724812 APL Cultivation]
== References ==
<references />
{{APL built-ins}}
{{APL built-ins}}

Navigation menu