A library for vector math in n dimensions.
ndvector is yet another vector math library for Python3. Where numpy focuses on everything including the kitchen sink, ndvector is intended to provide a simple, pythonic, object oriented API for vector math in n dimensions.
Apache License 2.0 (see LICENSE)
python >= 3.5
Usage attempts to be about what you expect. Simply import the library, create Point and Vector objects, and do math with them.
from n_dimension import Vector v1 = Vector(1.0, 0.0) v2 = Vector(-1.0, 1.0) v3 = v1 + v2 print(v3) # => Vector ‹0.0, 1.0›
- s a scalar (float) - p, p# are instances of Point - v, v# are instances of Vector
- constructor - create a Point from one or more float parameters, a tuple of floats, or a list of floats - properties: - dimension - the dimension of the Point - operators: - 'p + v' addition of a Vector to a Point to get the Point at the tip of the Vector if the tail of the vector is moved to the Point - 'p1 - p2' subtraction of a Point from a Point to get the Vector between the Points - 'p1 == p2' equality (See Note 1) - 'p1 != p2' not equality (See Note 1)
- constructor - create a Vector from one or more float parameters, a tuple of floats, or a list of floats - properties: - dimension - the dimension of the vector - magnitude - the magnitude of the vector - operators - 'v1 + v2' vector addition - 'v1 - v2' vector subtraction - 'v1 * v2' scalar aka dot product (v1 * v2 => scalar) - 'v * s' scale vector - 'v1 @ v2' vector aka cross product (v1 * v2 => vector) (See Note 2) - 'v1 == v2' equality (See Note 1) - 'v1 != v2' not equality (See Note 1) - methods - angle() - find the angle in radians between the vector and another vector - normalize() - find a unit vector with the same direction as the vector
- testing for equality when floats are involved is tricky. n_dimension considers two floats to be equal if the absolute value of their difference is less than a certain amount; currently 0.000001 seems to work well. This may be refined after more testing
- only implemented for Vectors of dimension three (3)
Testing is done using
https://tox.readthedocs.io/en/latest/ for information about installing tox.
Run the tests by cloning the source repository, changing into the local
working directory, and invoking
git clone https://github.com/tkegan/n_dimension.git cd n_dimension tox
Create better API documentation
Investigate accelerated performance by moving some functionality to compiled code but only if the pure python implementation can be kept as a fallback
I welcome pull requests against the GitHub repository. If extending the API, please include tests. I will not merge changes to the API until tests are in place and passing.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash||File type||Python version||Upload date|
|ndvector-1.0.0-py2-none-any.whl (9.5 kB) View hashes||Wheel||py2|
|ndvector-1.0.0.tar.gz (4.4 kB) View hashes||Source||None|