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 cells, such as the rows of a matrix, runs on every cell at once, in one batched call for each position along the axis.

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

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

M←[1 2 3◇4 5 6]
10 20+\⁰ ¹ 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 #⁻