The Vector library provides classes and utilities for representing 2D, 3D, and 4D vectors, primarily for scientific computing, especially within the Scikit-HEP ecosystem. It offers a NumPy-compatible interface for vector operations, with support for various backends including pure Python objects, NumPy arrays, Awkward Arrays, and Numba for JIT-compiled calculations. The current version is 1.8.0, and it maintains a regular release cadence with several minor versions released annually.
pip install vectorVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to import the `vector` library, create 2D and 4D vector objects using `vector.obj()`, access common properties like magnitude (`rho`) and transverse momentum (`pt`), perform vector addition, and calculate angular differences like `delta_phi`.
Upgrade to Python 3.10 or newer, or pin `vector` to an earlier compatible version (e.g., `<1.7.0` for Python 3.8, `<1.8.0` for Python 3.9).
Ensure your project uses Awkward Array v2 (e.g., `pip install 'awkward>=2.0.0'`).
If `vector==1.6.0` is in your dependencies, upgrade to `vector>=1.6.1` or the latest stable version.
pip install vector
Create a vector object first, then access its attributes: `v = vector.obj(x=1, y=2); print(v.x)`
Provide the required coordinates as keyword arguments: `v = vector.obj(x=1.0, y=2.0)` or `v = vector.obj(rho=1.0, phi=0.5)`
Ensure the input NumPy array is a structured array with fields corresponding to vector components, or use `vector.Array.from_fields()` for explicit control: `import numpy as np; import vector; arr = np.array([{'x': 1, 'y': 2}, {'x': 3, 'y': 4}]); v_arr = vector.Array(arr)`