Skip to content

vector

An infinite-dimensional vector Python package.

>>> from vector import vecadd
>>> vecadd((1, 2), (4, 5, 6))
(5, 7, 6)
>>> 
>>> from vector import Vector
>>> v = Vector((1, 2))
>>> w = Vector((4, 5, 6))
>>> v + w
Vector(5, 7, 6, ...)
>>> 
>>> from vector import vecnpadd
>>> vecnpadd((1, 2), ((3, 4, 5),
...                   (6, 7, 8)))
array([[4, 6, 5],
       [7, 9, 8]])

Installation

pip install git+https://github.com/goessl/vector.git

Usage

This package includes

  • general-purpose functions (prefixed vec...) in pure Python,
  • a clean class (Vector) with easy to use syntax,
  • improved numpy-routines (prefixed vecnp...) for parallelised operations &
  • tensor functions (prefixed ten...) for multiaxis operations

to handle type-independent, infinite-dimensional vectors. It operates on vectors of different lengths, treating them as infinite-dimensional by assuming that all components after the given ones are zero.

All vectors are zero-indexed.

Operation Functional Object-oriented Parallelised Multiaxis
Creation
Zero constant veczero Vector.ZERO vecnpzero tenzero
Basis vecbasis Vector vecnpbasis tenbasis
Random uniform vecrand Vector.rand vecnprand tenrand
Random normal vecrandn Vector.randn vecnprandn tenrandn
Utility
Dimensionality len vecnpdim tendim
Rank tenrank
Trimming vectrim .trim vecnptrim tentrim
Comparison veceq == vecnpeq
Rounding vecround .round vecnpround tenround
Right shift vecrshift >>
Left shift veclshift <<
Hilbert space
Norm vecabs abs vecnpabs
Norm squared vecabsq .absq vecnpabsq
Inner product vecdot @ vecnpdot
Parallelism vecparallel .is_parallel vecnpparallel
Vector space
Positive vecpos + vecnppos tenpos
Negative vecneg - vecnpneg tenneg
Addition vecadd + vecnpadd tenadd
Basis addition vecaddc .addc tenaddc
Subtraction vecsub - vecnpsub tensub
Multiplication vecmul * vecnpmul tenmul
True division vectruediv / vecnptruediv tentruediv
Floor division vecfloordiv // vecnpfloordiv tenfloordiv
Mod vecmod % vecnpmod tenmod
Divmod vecdivmod divmod tendivmod
Elementwise
Multiplication vechadamard .hadamard tenhadamard
True division vechadamardtruediv .hadamardtruediv tenhadamardtruediv
Floor division vechadamardfloordiv .hadamardfloordiv tenhadamardfloordiv
Mod vechadamardmod .hadamardmod tenhadamardmod
Min vechadamardmin .hadamardmin
Max vechadamardmax .hadamardmax

Prefix Design

Could use no prefix to be more mathematically pure, like add instead of vecadd, but then you would always have to use from vec import add as vecadd if used with other libraries (like operator).

Also avoids keyword collisions (abs is reserved, vecabs isn't).

Do it like numpy.polynomial.polynomial. ....

Roadmap

  • zip version between zip & zip_longest. Yields different sized tuples. Done: goessl/zipvar
  • vecdivmod
  • docstrings
  • numpy routines
  • multiaxis vectors: tensors?
  • Complexity analysis. Perfect complexity
  • dimensionality signature (e.g. vecadd: \(\mathbb{K}^m\times\mathbb{K}^n\to\mathbb{K}^{\max{m, n}}\))
  • vechadamardminmax
  • never use numpy.int64, they don't detect overflows
  • sparse vectors (dicts)
  • C++ & Java version

License (MIT)

Copyright (c) 2022-2025 Sebastian Gössl

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.