Qu

rows

Builtin index · Core maths

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.

CodeInputOutputDescription
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(x=[1,2,3], y=[10,20,-5])
print(df)
print("nrow = {nrow(df)}")
print("ncol = {ncol(df)}")
print("df.nrows = {df.nrows}")
print("rows(df) = {rows(df)}")
output
x   y
-  --
1  10
2  20
3  -5
nrow = 3
ncol = 2
df.nrows = 3
rows(df) = 3

from tour

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

net = simple_cnn([6, 6], 2, seed = 3)
img1 = zeros(6, 6)
img1[2, 2] = 1.0
img1[2, 3] = 1.0
img1[3, 2] = 1.0
img1[3, 3] = 1.0
img2 = zeros(6, 6)
img2[1, 2] = 1.0
img2[2, 1] = 1.0
img2[2, 3] = 1.0
img2[3, 2] = 1.0
net = net.fit((img1, img2), [0, 1], epochs = 5, lr = 0.1)
print("simple_cnn predict rows: {rows(net.predict((img1, img2)))}")

rnn = simple_rnn_classifier(1, 6, 2, seed = 5)
seq1 = [0.1, 0.3, 0.5, 0.7, 0.9] as matrix(1, 5)
seq2 = [0.9, 0.7, 0.5, 0.3, 0.1] as matrix(1, 5)
rnn = rnn.fit((seq1, seq2), [0, 1], epochs = 5, lr = 0.1)
print("simple_rnn_classifier predict rows: {rows(rnn.predict((seq1, seq2)))}")
output
simple_cnn predict rows: 2
simple_rnn_classifier predict rows: 2

from statistics-ml

seq = sequential_split(X, y, test_size = 0.2)
print("sequential_split train rows: {rows(seq.X_train)}")

strat = stratified_split(Xc, yc, test_size = 0.3, seed = 9)
print("stratified_split train rows: {rows(strat.X_train)}")

tvt = train_val_test_split(Xc, yc, val_size = 0.2, test_size = 0.2, seed = 9)
print("train/val/test rows: {rows(tvt.X_train)}, {rows(tvt.X_val)}, {rows(tvt.X_test)}")

m = knn_model(strat.X_train, strat.y_train, 5, kind = "classification")
confusion_matrix(strat.y_test, m.predict(strat.X_test), 2)
output
sequential_split train rows: 96
stratified_split train rows: 140
train/val/test rows: 120, 40, 40
0, 0: 29 29 0, 1: 0 0 1, 0: 2 2 1, 1: 29 29 0 1 0 1 constant-velocity Kalman filter

from statistics-ml

How it works

shape introspection

From the note above this builtin in the interpreter, where the reasoning was written down as it was built.

See also

cols — documented in the same entry.