Vocabulary/dollardot

From J Wiki
Jump to navigation Jump to search

>> <<   Down to: Dyad   Back to: Vocabulary Thru to: Dictionary

$. y Sparse

Rank Infinity -- operates on x and y as a whole -- WHY IS THIS IMPORTANT?



Gives a noun that can replace (numeric) y in working code, with only the non-zero atoms of $.y stored in memory. See the entry in the J Dictionary for details

When $.y is displayed in the J session, only its non-zero atoms are shown, together with their indexes.

   $ y=: 0 0 1 0 2.5 0 0 999 _ 0 0 0
12
   ] z=: $.y
2 |   1
4 | 2.5
7 | 999
8 |   _
   $ z
12

Common uses

To save storage when storing a sparse array.


Oddities

Operations on a sparse matrix can change the sparse value. Confusing to the unaware.

   $. 3 {. 1
0 │ 1
   
   NB. One might expect to see 999 here.
   999 * -. $. 3 {. 1
0 │ 0
   
   NB. the sparse element changed.
   3 $. 999 * -. $. 3 {. 1
999

x $. y Sparse

Rank Infinity -- operates on x and y as a whole -- WHY IS THIS IMPORTANT?



n&$. is a collection of functions for creating and handling sparse arrays and converting them to/from ordinary arrays.

The noun n can take one of the values 0 1 2 3 4 5 7 8 or their negations. See the entry in the J Dictionary for details of the actual function specified by n plus the form of the y-argument it expects.


Chapter 30 of 'Learning J' by Roger Stokes (also accessible via 'LJ' from the J Help pages) gently introduces to Sparse Arrays, going through various examples.