This is a pre-release version (2.5.0.dev0+git20251130.2de293a). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.5.0.dev0+git20251130.2de293a / numpy / strings / center

_ArrayFunctionDispatcher

numpy.strings:center

source: build-install/usr/lib/python3.14/site-packages/numpy/_core/strings.py :691

Signature

def   center ( a width fillchar = )

Summary

Return a copy of a with its elements centered in a string of length width.

Parameters

a : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype
width : array_like, with any integer dtype

The length of the resulting strings, unless width < str_len(a).

fillchar : array-like, with ``StringDType``, ``bytes_``, or ``str_`` dtype

Optional padding character to use (default is space).

Returns

out : ndarray

Output array of StringDType, bytes_ or str_ dtype, depending on input types

Notes

While it is possible for a and fillchar to have different dtypes, passing a non-ASCII character in fillchar when a is of dtype "S" is not allowed, and a ValueError is raised.

Examples

import numpy as np
c = np.array(['a1b2','1b2a','b2a1','2a1b']); c
np.strings.center(c, width=9)
np.strings.center(c, width=9, fillchar='*')
np.strings.center(c, width=1)

See also

str.center

Aliases

  • numpy.char.center