numel
result = numel(x)
Input: x · Output: result
What it is
Total element count of x: 1 for a scalar, its length for a Vec/CVec/Signal, rows*cols for a Mat, a Unicode-aware character count for a Str, and the element/node count for List/Record/Dict/fifo/linked_list/graph.
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = numel(x) | x scalar, Vec, CVec, Signal, Mat, Str, List, Record, or Dictnot 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.
s = "hello hello hello compression world"
enc = rans_encode(s)
print(numel(enc.bytes)) # coded length, in bytes
print(rans_decode(enc, as_str = true) == s) # true
output
18 true
from file-io
ys = [3, 1, 4, 1, 5]
print(contains(ys, 4)) # true
print(indexof(ys, 4)) # 2
print(cumsum(ys)) # [3, 4, 8, 9, 14]
print(numel(ys)) # 5
output
true 2 [3, 4, 8, 9, 14] 5
from collections-strings
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
length — documented in the same entry.