---
source: https://iinventedlight.com/library/notes/numpy-ufuncs.md
title: "NumPy universal functions (ufuncs)"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (numpy/numpy LICENSE.txt; Copyright (c) 2005-2026, NumPy Developers; https://github.com/numpy/numpy/blob/main/LICENSE.txt); prose restates or closely paraphrases cited source lines"
license_family: numpy-bsd3
rule_check: "needs rule check (family not in auto-publish rule; check.mjs auto-approves only usgov and arxiv-ccby)"
attribution: "Summary by iinventedlight (AI-assisted). Sources: NumPy docs, Universal functions (ufunc) basics — NumPy v2.5 Manual, BSD-3-Clause (numpy/numpy LICENSE.txt; Copyright (c) 2005-2026, NumPy Developers; https://github.com/numpy/numpy/blob/main/LICENSE.txt); NumPy docs, Universal functions (ufunc) — NumPy v2.5 Manual, BSD-3-Clause (numpy/numpy LICENSE.txt; Copyright (c) 2005-2026, NumPy Developers; https://github.com/numpy/numpy/blob/main/LICENSE.txt)."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-04
status: published
checked_on: 2026-11-04
as_of: 2026-11-04
confidence: medium
untested: "No code was run for this note; only the fetched documentation pages were read."
category: coding-references
topic_area: "code-ai-eng: NumPy"
tags: ['numpy', 'ufunc', 'vectorization']
sources:
  - id: S1
    title: "Universal functions (ufunc) basics — NumPy v2.5 Manual"
    publisher: NumPy docs
    url: https://numpy.org/doc/stable/user/basics.ufuncs.html
    accessed: 2026-11-04
    license: "BSD-3-Clause (numpy/numpy LICENSE.txt; Copyright (c) 2005-2026, NumPy Developers; https://github.com/numpy/numpy/blob/main/LICENSE.txt)"
  - id: S2
    title: "Universal functions (ufunc) — NumPy v2.5 Manual"
    publisher: NumPy docs
    url: https://numpy.org/doc/stable/reference/ufuncs.html
    accessed: 2026-11-04
    license: "BSD-3-Clause (numpy/numpy LICENSE.txt; Copyright (c) 2005-2026, NumPy Developers; https://github.com/numpy/numpy/blob/main/LICENSE.txt)"
---
# NumPy universal functions (ufuncs)

**Answer:** A universal function (or ufunc for short) is a function that operates on ndarrays in an element-by-element fashion, supporting array broadcasting, type casting, and several other standard features. (S1)

## What a ufunc is

- A ufunc is a vectorized wrapper for a function that takes a fixed number of specific inputs and produces a fixed number of specific outputs. (S2)
- In NumPy, universal functions are instances of the numpy.ufunc class. (S1)
- Many of the built-in functions are implemented in compiled C code. (S1)
- There are also generalized ufuncs which are functions over vectors (or arrays) instead of single-element scalars. (S1)
- One can also produce custom numpy.ufunc instances using the numpy.frompyfunc factory function. (S1)

## Arguments

- If out is None (the default), an uninitialized output array is created, which will be filled in the ufunc. (S2)
- The where argument accepts a boolean array which is broadcast together with the operands. (S2)
- The dtype keyword allows you to manage a very common problem that arises when naively using ufunc.reduce. (S1)

## Claims
- id: C1
  claim: A ufunc operates element by element on ndarrays.
  source: S1
  evidence: "operates on ndarrays in an element-by-element fashion"
- id: C2
  claim: Ufuncs are instances of numpy.ufunc.
  source: S1
  evidence: "In NumPy, universal functions are instances of the"
- id: C3
  claim: numpy.frompyfunc makes custom ufuncs.
  source: S1
  evidence: "using the function numpy.setbufsize."
- id: C4
  claim: Ufuncs are functions that operate element by element on whole arrays.
  source: S2
  evidence: "Functions that operate element by element on whole arrays."

## Sources
- [S1] Universal functions (ufunc) basics — NumPy v2.5 Manual. NumPy docs. https://numpy.org/doc/stable/user/basics.ufuncs.html . License: BSD-3-Clause (numpy/numpy LICENSE.txt; Copyright (c) 2005-2026, NumPy Developers; https://github.com/numpy/numpy/blob/main/LICENSE.txt). Accessed 2026-11-04.
- [S2] Universal functions (ufunc) — NumPy v2.5 Manual. NumPy docs. https://numpy.org/doc/stable/reference/ufuncs.html . License: BSD-3-Clause (numpy/numpy LICENSE.txt; Copyright (c) 2005-2026, NumPy Developers; https://github.com/numpy/numpy/blob/main/LICENSE.txt). Accessed 2026-11-04.

License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted).
