⍴ — Shape / Reshape

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

⍴Y gives axis lengths.

⍴2 3⍴0             ⍝ [2 3]ₓ

The shape is keyed by the axis names. An unnamed axis gives an unkeyed entry. See named axes.

M←["city":2 "month":3]⍴⍳6
⍴M                 ⍝ ["city":2 "month":3]ₓ
"month"⌷⍴M         ⍝ 3ₓ

S⍴Y reshapes, cycling or truncating the ravel of Y. Dimensions are nonnegative integers. Empty Y supplies fill.

2 3⍴1 2            ⍝ [1 2 1⋄2 1 2]
3⍴""               ⍝ "   "

An empty shape makes a rank-zero array.

⍬⍴1 2              ⍝ ⊂1

A keyed S names the axes of the result. An unkeyed S gives no names. When S matches the shape of Y, the result keeps the position keys of Y.

⍴["city":2 3]⍴⍳6   ⍝ ["city":2 3]ₓ

Inverse

S⍴⁻¹Y ravels Y, which must have shape S.

2 3⍴⁻¹2 3⍴⍳6   ⍝ 0 1 2 3 4 5