cols
result = rows(A)
Input: A · Output: result
What it is
Row / column count of A. On a Vec (shape (n, 1)), a Mat/Signal (shape (r, c)), or a bare scalar (shape (1, 1)), returns the corresponding dimension as a scalar Num. On a Table, returns the same values as nrow(df)/ncol(df) — row count is the record count, column count the field count.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = rows(A) | A Vec, Mat, Signal, scalar, Num, or Tablenot documented yet | result scalar or Num | Returns a scalar Num. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
df = table(a = randn(30, seed = 3), b = randn(30, seed = 4), c = randn(30, seed = 5))
eda(df) # correlation heatmap + one histogram per numeric column, auto-gridded
print("columns: " + str(cols(df)))
output
columns: 3
from plotting
function summarize(m: model<"qr">)
return "qr: q is {rows(m.q)}x{cols(m.q)}, r is {rows(m.r)}x{cols(m.r)}"
end function
function summarize(m: model<"svd">)
return "svd: singular values = {m.s}"
end function
function summarize(m: model)
return "generic model, kind unhandled"
end function
A = [4, 3; 6, 3]
qres = qr(A)
sres = svd(A)
pk = findpeaks([0,1,3,1,0,2,4,2,0])
print(summarize(qres))
print(summarize(sres))
print(summarize(pk))
from tour
Fs = 2000
fc = 60
lp = butter(4, "low", fc, Fs)
print("Butterworth order 4, cutoff {fc} Hz @ Fs={Fs} Hz -- sos shape: {rows(lp.sos)}x{cols(lp.sos)}")
N = 1000
t = (0 to N - 1) / Fs
low_tone = sin(2*pi*20*t)
high_tone = sin(2*pi*400*t)
mix = low_tone + high_tone
causal = sosfilt(lp, mix)
zerophase = filtfilt(lp, mix)
err_low_causal = rms(causal[100:N-1] - low_tone[100:N-1])
err_low_zp = rms(zerophase[100:N-1] - low_tone[100:N-1])
print("20 Hz tone RMS recovery error: causal={err_low_causal:.4f}, zero-phase={err_low_zp:.4f}")
print("High tone (400 Hz) amplitude in raw mix: {rms(high_tone):.4f}")
print("High tone leakage after zero-phase LP: {rms(zerophase - low_tone):.4f}")
from tour
G = vstack(randn(40, 2, seed = 31) + 4,
randn(40, 2, seed = 32) - 4,
randn(40, 2, seed = 33))
d = dbscan(G, 1.5, 4)
print("dbscan labels: {distinct(d)}")
proj = pca(G, 2) # the (n, 2) projected coordinates
comps = pca_components(G, 2) # the (2, 2) loading matrix
ev = pca_explained_variance(G, 2)
print("pca projected shape: {rows(proj)} x {cols(proj)}")
print("pca components:\n{round(comps, 3)}")
print("explained variance: {round(ev, 3)}")
small = vstack(randn(6, 2, seed = 41) + 3, randn(6, 2, seed = 42) - 3)
low = tsne(small, n_components = 2, perplexity = 3, seed = 1, max_iter = 100)
print("tsne output rows: {rows(low)}")
output
dbscan labels: (0, 1, 2) pca projected shape: 120 x 2 pca components: [0.694, 0.72; 0.72, -0.694] explained variance: [0.969, 0.031] tsne output rows: 12
from statistics-ml
See also
rows — documented in the same entry.