Vocabulary/semidot0
>> << Down to: Dyad Back to: Vocabulary Thru to: Dictionary
u;.0 y Reversed Adverb
Rank Infinity -- operates on x and y as a whole -- WHY IS THIS IMPORTANT?
Trivial case: If y is a list, u;.0 y is the same as u |. y .
y=. 2 3 5 7 NB. a list u=. -: NB. some verb |. y NB. using Reverse 7 5 3 2 u |. y NB. applying verb 3.5 2.5 1.5 1 u;.0 y NB. using verb with adverb Reversed (to the same effect) 3.5 2.5 1.5 1
In general, u;.0 y reverses y along all its axes, and then applies the verb u to the reversed y.
] y=. 2 3 $ p: i.6 NB. an array 2 3 5 7 11 13 u=. <: NB. some verb |. y NB. reversing at horizontal axis 7 11 13 2 3 5 |."1 |. y NB. reversing at vertical axis as well 13 11 7 5 3 2 u;.0 y NB. Reversed reverses along *all* axes before applying verb 12 10 6 4 2 1
Common uses
1. Apply u to the reversal of y:
isinstring =: +./@:E. NB. 1 if x is found in y 'ode'&isinstring 'boustrophedonic' 0 'ode'&isinstring;.0 'boustrophedonic' 1
Related Primitives
Reverse (|. y)
x u;.0 y Subarray Adverb
Rank 2 _ -- operates on tables of x and the entirety of y -- WHY IS THIS IMPORTANT?
In x u;.0 y, x describes a subarray of y. The subarray is extracted from y, and then verb u is applied to it.
In these examples u is ], which simply passes the selected subarray unchanged.
]a =. a. {~ (a. i. 'a') + i. 4 4 NB. A 4x4 array abcd efgh ijkl mnop (0 0 ,: 2 2) ];.0 a NB. starting at 0 0, take a subarray of shape 2 2 ab ef (1 2 ,: 3 2) ];.0 a NB. Starting at 1 2, take a subarray of shape 3 2 gh kl op
Argument x is a table with two rows. Each column of x gives the selection for the corresponding axis of y. The first number in each column gives the starting position, and the second number gives the number of items selected.
Looking at it another way, the first row of x is the index list of the starting corner of the subarray, and the second item gives the shape of the subarray.
Common uses
1. Use x ];.0 y to extract a subarray. It is the fastest way to do it.
2. The substr function, which extracts a substring from a string, can be coded using x ];.0 y
substr =: (];.0~ ,.)~"1 NB. x is (start,len), y is string to take from 2 4 substr 'boustrophedonic' ustr
3. If you want to apply a verb to the subarray, use that verb as u
(0 0 ,: 2 2) ,;.0 a NB. Select subarray, then enfile into a list abef
4. x ];.0 y can be used to perform the function of x {. y, but without overtaking:
3 ];.0 i. 5 0 1 2 5 ];.0 i. 3 0 1 2
Details
1. If the length causes the subarray to extend past the end of the array, the subarray is truncated at the end of the array. The resulting length may be 0.
(1 2 ,: 2 8) ];.0 a gh kl
2. A length of infinity (_ or __) means "to the end of the array".
(2 ,: _) ];.0 'abcdefgh' cdefgh
3. If x is an atom or a list, it calls for a subarray whose shape is ,x, starting at the beginning of the array. In other words, x is treated as the second row of the left argument, and the first row is taken to be 0.
2 3 ];.0 a abc efg
4. If x has fewer columns than the rank of y, trailing columns of 0 _ are added, which take the omitted axes in their entirety
(2,:2) ];.0 a ijkl mnop
5. If a starting position is negative, it indicates a position relative to the end of that axis, and is used as the ending position of the selection
Note: even though the selected region runs backwards from the start position, the selection retains its normal order
(2 _1 ,: 2 2) ];.0 a kl op
6. If a length is negative, that axis is reversed after the selection.
(2 _1 ,: 2 _2) ];.0 a NB. Axis 1 reversed lk po
7. The starting position must be a valid atom of the array, or one atom before or after the array (in which case the length of the result will always be 0).
8. The subarray of y always has the same rank as y.
9. If x has no columns, it selects all of y.
10. Bug: if x is an empty array containing no rank-2 subarrays (example: 0 2 2$0), u is applied to y instead of an empty subarray of y.
Use These Combinations
Combinations using x ;.0 y that have exceptionally good performance include:
What it does Type;
Precisions;
RanksSyntax Variants;
Restrictions
Benefits;
Bug Warnings
Extract multiple substrings into a list Boolean list, byte list x ;@:(<;.0) y or [: ; <;.0 avoids boxing, avoids creating subarrays Extract substring/subarray table or list x ];.0 y or [;.0 avoids creating indexes