Qu

size

Builtin index · Core maths

result = shape(A)

Input: A · Output: result

What it is

The full shape of A as a 2-element Vec, [rows, cols], using the same per-type shape rules as rows/cols above. size is the same builtin — MATLAB's name for it. (sizeof is a third name for it and is deprecated: it means a byte count everywhere else). An Image is the one exception and reports [width, height], not rows-first — because an image's own constructors are width-first (image_new(width, height), resize(img, width, height), crop(img, x0, y0, width, height)), and answering rows-first made image_new(640, 480) report [480, 640]. A Mat of pixels is still a matrix and still [rows, cols].

Overloads

One call shape — this function is not overloaded.

CodeInputOutputDescription
result = shape(A)
A Vec, Image, Mat, or matrixnot documented yet
result Vec
Returns a 2-element Vec.

Examples

From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.

a = rand(3)
print("shape a: {size(a)}")

seed(5)
p = rand(2, 2)
junk = rand(2, 2, seed=42)
q = rand(2, 2)

seed(5)
p2 = rand(2, 2)
q2 = rand(2, 2)

print("q == q2: {q == q2}")
output
shape a: [3, 1]
q == q2: [1, 1; 1, 1]

from repl-diagnostics

A = [1, 2, 3; 4, 5, 6]
print("size={size(A)}  numel={numel(A)}")
print(eye(3))
print(identity(2))
p = [1, 2]
q = [3, 4]
print(cat(1, p, q))   # vertical: stacks rows

print(cat(2, p, q))   # horizontal: concatenates

output
size=[2, 3]  numel=6
[1, 0, 0; 0, 1, 0; 0, 0, 1]
[1, 0; 0, 1]
[1, 2; 3, 4]
[1, 2, 3, 4]

from core-math

See also

shape — documented in the same entry.