Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sequence 📿

An ordered collection of hypervectors with positional encoding. See Composites: Sequence for the conceptual overview.

Constructor

# Constructing a sequence, with logical index start at 1 (default to 0).
seq = hv.Sequence(hv.Seed128(0, 42), first, second, third, start=1)

In-place edits: Append / Prepend / Reset

Append, Prepend, and Reset all mutate the Sequence in place — clone first if you need to preserve the original.

  • Append(more...) — add members at the end. start is unchanged.
  • Prepend(more...) — add members at the front; start decrements by len(more) so existing members keep their positional binding.
  • Reset(start) — shift the starting index. No-op when start equals the current start.

After any of these, seq equals what you’d get by building a fresh NewSequence(seed, new_start, all_members...) — the domain/pod seed is preserved.

import copy

seq = hv.Sequence(hv.Seed128(0, 42), a, b, c)

# Append / Prepend are variadic and mutate in place.
seq.append(d, e)            # seq now [a, b, c, d, e]
seq.prepend(x, y)           # seq now [x, y, a, b, c, d, e], start -= 2
seq.reset(10)               # shift the starting index to 10

# To preserve the original, clone first:
base = hv.Sequence(hv.Seed128(0, 42), a, b, c)
s1 = copy.copy(base)
s1.append(d)                # base is untouched
Last change: , commit: 0642da6