{"id":5823,"library":"vector","title":"Vector","description":"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.","status":"active","version":"1.8.0","language":"python","source_language":"en","source_url":"https://github.com/scikit-hep/vector","tags":["physics","mathematics","vectors","scikit-hep","numba","awkward","geometry","lorentz"],"install":[{"cmd":"pip install vector","lang":"bash","label":"Install stable version"}],"dependencies":[{"reason":"Requires Python >=3.10. Older versions of the library supported older Python versions (e.g., v0.9.0 supported 3.6+).","package":"python","optional":false},{"reason":"Core dependency for array-based vector operations and numerical computations.","package":"numpy","optional":false},{"reason":"Optional backend for manipulating arrays of vectors with Awkward Array. Requires Awkward Array v2+ since vector v1.5.0.","package":"awkward","optional":true},{"reason":"Optional backend for JIT-compiled calculations on vectors, particularly with NumPy and Awkward Arrays.","package":"numba","optional":true},{"reason":"Optional backend for symbolic (non-numeric) manipulations of vector expressions.","package":"sympy","optional":true}],"imports":[{"note":"The main entry point for creating vector objects and accessing utilities.","symbol":"vector","correct":"import vector"},{"note":"Used to create a single pure Python vector object.","symbol":"vector.obj","correct":"my_vec = vector.obj(x=1, y=2)"},{"note":"Used to create a NumPy array of vector objects. Also accessible via `vector.array`.","symbol":"vector.arr","correct":"vec_array = vector.arr(x=[1,2,3], y=[4,5,6])"},{"note":"Used to create an Awkward Array of vector objects. Also accessible via `vector.Array`.","symbol":"vector.awk","correct":"awk_array = vector.awk(x=ak.Array([1,2]), y=ak.Array([3,4]))"}],"quickstart":{"code":"import vector\n\n# Create a 2D Cartesian vector\nv2d = vector.obj(x=3, y=4)\nprint(f\"2D vector: {v2d}\")\nprint(f\"Magnitude: {v2d.rho}\")\n\n# Create a 4D Lorentz vector (momentum-like)\nv4d = vector.obj(px=10, py=20, pz=30, mass=5)\nprint(f\"4D vector (momentum): {v4d}\")\nprint(f\"Transverse momentum: {v4d.pt}\")\n\n# Add two vectors\nv_sum = v2d + vector.obj(x=1, y=1)\nprint(f\"Vector sum: {v_sum}\")\n\n# Calculate delta_phi between two 2D vectors\nv1 = vector.obj(x=1, y=0)\nv2 = vector.obj(x=0, y=1)\ndelta_phi = v1.delta_phi(v2)\nprint(f\"Delta phi between v1 and v2: {delta_phi}\")","lang":"python","description":"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`."},"warnings":[{"fix":"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).","message":"Support for older Python versions has been dropped in recent releases. Vector v1.8.0 requires Python 3.10+, and v1.7.0 dropped Python 3.8 support. Users on older Python environments must use an earlier version of the `vector` library.","severity":"breaking","affected_versions":">=1.7.0"},{"fix":"Ensure your project uses Awkward Array v2 (e.g., `pip install 'awkward>=2.0.0'`).","message":"Support for Awkward Array v1 was removed in `vector` v1.5.0. If you use `vector` with Awkward Arrays, you must upgrade to Awkward Array v2 or later.","severity":"breaking","affected_versions":">=1.5.0"},{"fix":"If `vector==1.6.0` is in your dependencies, upgrade to `vector>=1.6.1` or the latest stable version.","message":"Version 1.6.0 of the `vector` library was yanked from PyPI shortly after its release due to a bug where `numpy` functions were incorrectly called on `TypeTracerArray`s. It is recommended to avoid this specific version.","severity":"gotcha","affected_versions":"1.6.0"}],"env_vars":null,"search_vec":"'1.8.0':61 '2d':11 '3d':12 '4d':14 'annual':74 'array':47,49 'awkward':48,82 'backend':41 'cadenc':68 'calcul':56 'class':6 'compat':32 'compil':55 'comput':19 'current':58 'ecosystem':26 'especi':20 'geometri':83 'hep':25,80 'includ':42 'interfac':33 'jit':54 'jit-compil':53 'librari':4 'lorentz':84 'maintain':64 'mathemat':76 'minor':71 'numba':51,81 'numpi':31,46 'numpy-compat':30 'object':45 'offer':28 'oper':36 'physic':75 'primarili':16 'provid':5 'pure':43 'python':44 'regular':66 'releas':67,73 'repres':10 'scientif':18 'scikit':24,79 'scikit-hep':23,78 'sever':70 'support':38 'util':8 'various':40 'vector':1,3,15,35,77 'version':59,72 'within':21","created_at":"2026-04-14T05:08:45.044382+00:00","updated_at":"2026-04-17T00:12:01.411554+00:00","problems":[{"fix":"pip install vector","cause":"The 'vector' library has not been installed in the current Python environment.","error":"ModuleNotFoundError: No module named 'vector'"},{"fix":"Create a vector object first, then access its attributes: `v = vector.obj(x=1, y=2); print(v.x)`","cause":"The coordinate 'x' is an attribute of a 'vector' instance (e.g., a 2D vector object), not a property directly accessible from the top-level 'vector' module.","error":"AttributeError: module 'vector' has no attribute 'x'"},{"fix":"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)`","cause":"When creating a 2D vector using `vector.obj()`, the required coordinate arguments (e.g., 'x' and 'y' for Cartesian, or 'rho' and 'phi' for polar) were not provided as keyword arguments.","error":"TypeError: obj() missing 2 required keyword-only arguments: 'x' and 'y'"},{"fix":"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)`","cause":"When attempting to create a 'vector.Array' from a NumPy array, the input array was not in the expected structured format with named fields for vector components (e.g., 'x', 'y').","error":"ValueError: array must be an Awkward Array, NumPy structured array, or an object that contains either 'x', 'y', 'z', 't', 'rho', 'phi', 'theta', 'tau', 'px', 'py', 'pz', 'E', 'eta', 'rapidity', 'pt'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.8.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/scikit-hep/vector","docs":"https://vector.readthedocs.io/","changelog":"https://vector.readthedocs.io/en/latest/changelog.html","pypi":"https://pypi.org/project/vector/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","ai-ml"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-31","next_check":"2026-07-28","install_tag":null}}