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).
License: CC-BY-4.0 · 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).
Cite this
iinventedlight. 2026. "NumPy universal functions (ufuncs)." iinventedlight Library, iil:note:5e3q85rn, version of 2026-11-04. https://iinventedlight.com/library/notes/numpy-ufuncs/. License: CC-BY-4.0.
@misc{iil_note_5e3q85rn,
author = {{iinventedlight}},
title = {{NumPy universal functions (ufuncs)}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-04},
url = {https://iinventedlight.com/library/notes/numpy-ufuncs/},
note = {Permanent ID iil:note:5e3q85rn. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com.
For language models and agents: start at /llms.txt. This page in Markdown: /library/notes/numpy-ufuncs.md.