Vector

1.8.0 · active · verified Tue Apr 14

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.

Warnings

Install

Imports

Quickstart

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`.

import vector

# Create a 2D Cartesian vector
v2d = vector.obj(x=3, y=4)
print(f"2D vector: {v2d}")
print(f"Magnitude: {v2d.rho}")

# Create a 4D Lorentz vector (momentum-like)
v4d = vector.obj(px=10, py=20, pz=30, mass=5)
print(f"4D vector (momentum): {v4d}")
print(f"Transverse momentum: {v4d.pt}")

# Add two vectors
v_sum = v2d + vector.obj(x=1, y=1)
print(f"Vector sum: {v_sum}")

# Calculate delta_phi between two 2D vectors
v1 = vector.obj(x=1, y=0)
v2 = vector.obj(x=0, y=1)
delta_phi = v1.delta_phi(v2)
print(f"Delta phi between v1 and v2: {delta_phi}")

view raw JSON →