项目作者: lace

项目描述 :
Linear algebra for humans
高级语言: Python
项目地址: git://github.com/lace/vg.git
创建时间: 2018-10-02T23:30:56Z
项目社区:https://github.com/lace/vg

开源协议:BSD 2-Clause "Simplified" License

下载


vg

version
python version
license

build
code style

A very good vector-geometry toolbelt for dealing with 3D points and
vectors. These are simple NumPy operations made readable, built to scale
from prototyping to production.

:book: See the complete documentation: https://vgpy.dev/

Examples

Normalize a stack of vectors:

  1. # 😮
  2. vs_norm = vs / np.linalg.norm(vs, axis=1)[:, np.newaxis]
  3. # 😀
  4. vs_norm = vg.normalize(vs)

Check for the zero vector:

  1. # 😣
  2. is_almost_zero = np.allclose(v, np.array([0.0, 0.0, 0.0]), rtol=0, atol=1e-05)
  3. # 🤓
  4. is_almost_zero = vg.almost_zero(v, atol=1e-05)

Find the major axis of variation (first principal component):

  1. # 😩
  2. mean = np.mean(coords, axis=0)
  3. _, _, pcs = np.linalg.svd(coords - mean)
  4. first_pc = pcs[0]
  5. # 😍
  6. first_pc = vg.major_axis(coords)

Compute pairwise angles between two stacks of vectors:

  1. # 😭
  2. dot_products = np.einsum("ij,ij->i", v1s.reshape(-1, 3), v2s.reshape(-1, 3))
  3. cosines = dot_products / np.linalg.norm(v1s, axis=1) / np.linalg.norm(v2s, axis=1)
  4. angles = np.arccos(np.clip(cosines, -1.0, 1.0))
  5. # 🤯
  6. angles = vg.angle(v1s, v2s)

Installation

  1. pip install numpy vg

Usage

  1. import numpy as np
  2. import vg
  3. projected = vg.scalar_projection(
  4. np.array([5.0, -3.0, 1.0]),
  5. onto=vg.basis.neg_y
  6. )

Development

First, install Poetry.

After cloning the repo, run ./bootstrap.zsh to initialize a virtual
environment with the project’s dependencies.

Subsequently, run ./dev.py install to update the dependencies.

Acknowledgements

This collection was developed at Body Labs by Paul Melnikow and extracted
from the Body Labs codebase and open-sourced as part of blmath by Alex
Weiss
. blmath was subsequently forked by Paul Melnikow and later
the vx namespace was broken out into its own package. The project was renamed
to vg to resolve a name conflict.

License

The project is licensed under the two-clause BSD license.