rows
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(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
colors = ("red", "green", "blue", "green", "red", "blue", "green", "red")
e = label_encode(colors)
print("classes: {e.classes}")
print("codes: {e.codes}")
print("back: {label_decode(e.codes, e.classes)}")
oh = one_hot(colors)
print("one_hot is {rows(oh.matrix)} x {cols(oh.matrix)}, columns = {oh.classes}")
output
classes: ("blue", "green", "red")
codes: [2, 1, 0, 1, 2, 0, 1, 2]
back: ("red", "green", "blue", "green", "red", "blue", "green", "red")
one_hot is 8 x 3, columns = ("blue", "green", "red")from statistics-ml
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
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.