vectors of n dimensions
Project description
mvec
a simple package for handling vectors of any size.
all* your favorite vector operations are here, and generalized to n-dimensional vectors. want to add three 4D vectors? dot product a 8D and 3D vector together? you can do it!
*disclaimer: i still haven't figured out how to implement the cross product in n dimensions, so right now, it only works on vectors <= 3 dimensions. sorry
examples
defining a vector is as simple as passing the constructor an n-dimensional array of scalar values!
v = Vector([a, b, c,... y, z])
you can also create Vectors in other ways:
# the vector between two points in n-dimensional space
v2 = Vector.fromTwoPoints([a₁, b₁, c₁,...], [a₂, b₂, c₂,...])
# for the special case of 3D vectors in a spherical coordinate system
v3 = Vector.fromSpherical(r, θ, φ)
from there, you can do all sorts of fun unary and binary operations!
v3 = v1.unitVector()
# returns the sector the vector is in, given as an array made up of either 1, 0, or -1
array = v1.sector()
# x(), y(), and z() are convenience methods to return the 1st, 2nd, or 3rd-dimensional component of a vector
f = v1.x()
v2 = v1.scale(7)
boolean = v1.parallel(v2)
boolean = v1.perpendicular(v2)
# returns the angle between v1 and v2
angle = v1.angleTo(v2)
v3 = v1.dot(v2)
v3 = v1.cross(v2)
and more! you can also access various components of the vectors:
# returns the components of a vector as a list
array = v1.toArray()
# returns the angle the vector makes from the positive axis in the i dimension (x = 0, y = 1, etc)
angle = v1.alphaRad(i)
you can also use built-in operators to do math with vectors and scalars!
# v2 is a vector in the same direction as v1 but its length is 5 more
v2 = v1 + 5
# v1 is now the difference between v1 and v2
v1 -= v2
v3 = v1 + v2
# equivalent to scaling v1 by 6 or 1/5 respectively
v2 = v1 * 6
v1 =/ 5
# compares magnitudes
v1 >= v2
v1 < v2
you can also iterate over the components of a vector:
v1 = Vector([2, 4, 6])
for i in v1:
print(i)
# 2
# 4
# 6
# >>>
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mvec-1.0.0.tar.gz.
File metadata
- Download URL: mvec-1.0.0.tar.gz
- Upload date:
- Size: 5.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
72a22fde4babf8f27de0815a47bae52d1b74a2271126b81644271cc50fdb4610
|
|
| MD5 |
d6e2b7b12db7d9dfe2ef58c79f6994bb
|
|
| BLAKE2b-256 |
b5cee4d7d6475f82293404be14dbae13e97797beb2498595203be79d4122e375
|
File details
Details for the file mvec-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mvec-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.5.0.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dc4f9534c05dcc42eeca419c514e47b05ac600ab95bf1838c593aeb6a6ca5c57
|
|
| MD5 |
372fcbc7a4d01a14555fe48b1fcb786d
|
|
| BLAKE2b-256 |
89f4ce1947512a425668dc5ccbc72e0b8124809d88fc6299a58156c1d7d04fa1
|