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.

Operation Functional Object-oriented Parallelised Multidimensional
creation
zero veczero Vector.ZERO vecnpzero tenzero
basis vecbasis Vector vecnpbasis tenbasis
rand vecrand Vector.rand vecnprand tenrand
randn vecrandn Vector.randn vecnprandn tenrandn
utility
dimensionality len vecnpdim tendim
rank tenrank
comparison veceq == vecnpeq
trimming vectrim .trim vecnptrim tentrim
rounding vecround .round vecnpround tenround
shifting vecrshift, veclshift >>, <<
Hilbert space
norm vecabsq .absq vecnpabsq
norm squared vecabs abs vecnpabs
dot 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
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

todo

  • [x] zip version between zip & zip_longest. Yields different sized tuples. Done: goessl/zipvar
  • [x] docstrings
  • [x] numpy routines
  • [x] multiaxis vectors: tensors?
  • [ ] never use numpy.int64, they don't detect overflows
  • [ ] sparse vectors (dicts)

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.