Skip to main content

\ — Scan

Monadic operator. Hanzi: 累

f\Y scans the last axis from left to right. Each result combines the previous result, as f’s left argument, with the next item: -\1 2 3 is 1, 1-2 and (1-2)-3.

+\1 2 3            ⍝ 1 3 6
-\1 2 3            ⍝ 1 ¯1 ¯4

S f\ Y uses the seed S as the previous result for the first item. The result doesn’t include the seed.

A dfn that scans several lanes, such as each row of a matrix, runs each stage on every lane at once, in a batched call. The result is the same as scanning each lane in turn.

10-\1 2 3          ⍝ 9 7 4
100+\10 20         ⍝ 110 130

Each lane starts from the whole seed. Use Rank for separate seeds per cell.

M←[1 2 3⋄4 5 6]
10 20+\⍤0 1 M      ⍝ [11 13 16⋄24 29 35]
[10]+\1 2 3        ⍝ [[11] [13] [16]]

An empty scan, or an unseeded scan of one item, doesn’t call f. Axis ⍠K chooses the axis to scan. ⍀ scans the first axis.

+\₀[1 2 3⋄4 5 6]    ⍝ [1 2 3⋄5 7 9]

APL difference: every scan left-accumulates, including dfns.

Inverse

f\⁻ undoes f\ when f has an inverse.

+\⁻1 3 6   ⍝ 1 2 3

Errors

  • DOMAIN: a subject operand. Expand with #⁻