Reference · Vectors

vec.zeros

signature
vec.zeros(int) -> list

What it does

A list of n ints, all 0. For zeros as floats multiply by 0.0, or use vec.full(n, 0.0).

Examples

print(vec.zeros(3))print(vec.zeros(0))
output
[0, 0, 0][]

Edge cases

print(vec.zeros(2) | vec.add(1))print(vec.zeros(2) | vec.add(0.5))print(vec.zeros(2.0))print(vec.full(2, 0.0))
output
[1, 1][0.5, 0.5][0, 0][0.0, 0.0]

Errors

A negative count, or one over ten million, is a runtime error, not an error value; so is a count that is not an int.

this one fails
print(vec.zeros(-1))
output
line 1: `vec.zeros`: -1 is not a count from 0 to 10000000
this one fails
print(vec.zeros("3"))
output
line 1: `vec.zeros` expects an int as argument 1, got str

Chaining

A row of counters to add into, or a blank matrix built from rows:

print(vec.zeros(4) | len)print(range(2) | map((i) => vec.zeros(3)))
output
4[[0, 0, 0], [0, 0, 0]]

See also

vec.ones, vec.full, vec.arange, vec.linspace

Thread
7Useful? Like it, or add to its thread below.

Thread 0 posts

On vec.zeros(): questions, tips, corrections, and code that uses it.

No posts yet. The first one opens the thread.

    Edit this page on GitHub · every example's output was made by running it (tools/refcheck.mjs) · questions on Discord or r/quillo