Qu

shape

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.

print(shape([[1, 2], [3, 4]]))            # [4, 1]   -- a column vector

print(shape([1, 2, 3, 4] as matrix(2, 2)))  # [2, 2]

output
[4, 1]
[2, 2]

from agent-guide

fs = 1000
lp = butter(4, "low", 100, fs)
bp = butter(4, "band", [80, 120], fs)
print("lowpass sections: {shape(lp.sos)[0]}")    # lowpass sections: 2

print("bandpass sections: {shape(bp.sos)[0]}")   # bandpass sections: 4

output
lowpass sections: 2
bandpass sections: 4

from signal-processing

fs = 1000
lp = ellip(4, 1, 40, "low", 100, fs)
bp = ellip(4, 1, 40, "band", [80, 120], fs)
print("lowpass sections: {shape(lp.sos)[0]}")    # lowpass sections: 2

print("bandpass sections: {shape(bp.sos)[0]}")   # bandpass sections: 4

output
lowpass sections: 2
bandpass sections: 4

from signal-processing

fs = 1000
lp = cheby1(4, 1, "low", 100, fs)
bp = cheby1(4, 1, "band", [80, 120], fs)
print("lowpass sections: {shape(lp.sos)[0]}")    # lowpass sections: 2

print("bandpass sections: {shape(bp.sos)[0]}")   # bandpass sections: 4

output
lowpass sections: 2
bandpass sections: 4

from signal-processing

See also

size — documented in the same entry.