Skip to main content

ρ — Shape / Reshape

Function. Keys: Alt-r. Hanzi: 形. Ranks: ∞ monadic, 1 ∞ dyadic

ρY gives axis lengths.

ρ2 3ρ0             ⍝ [2 3]ₓ

The shape is keyed by the axis names. The length of an unnamed axis has no key. See named axes.

M←["city":2 "month":3]ρι6ₓ
ρM                 ⍝ ["city":2 "month":3]ₓ
"month"⌷ρM         ⍝ 3ₓ

SρY reshapes, cycling or truncating the items of ,Y. Items of S are nonnegative whole numbers. With empty Y, every item is fill, which ⍠ can set.

2 3ρ1 2            ⍝ [1 2 1◇2 1 2]
3ρ""               ⍝ "   "

With empty S, the result is a scalar.

⍬ρ1 2              ⍝ ⊂1

The keys of S name the result’s axes. An unkeyed item leaves its axis unnamed. When S matches the shape of Y, the result keeps the keys of Y.

ρ["city":2 3]ρι6ₓ   ⍝ ["city":2 3]ₓ

Inverse

Sρ⁻Y gives ,Y. The axis lengths of Y must match S.

2 3ρ⁻2 3ρι6ₓ   ⍝ [0 1 2 3 4 5]ₓ

Errors

  • DOMAIN: an item of S isn’t a nonnegative whole number, or, for ρ⁻, the shape of Y isn’t S
  • LIMIT: the result has too many items