bundles / numpy latest / numpy / strings / encode
_ArrayFunctionDispatcher
numpy.strings:encode
source: build-install/usr/lib/python3.14/site-packages/numpy/_core/strings.py:584
Signature
def encode(a, encoding = None, errors = None)Summary
Calls str.encode element-wise.
Extended Summary
The set of available codecs comes from the Python standard library, and may be extended at runtime. For more information, see the codecs module.
Parameters
a: array_like, with ``StringDType`` or ``str_`` dtypeencoding: str, optionalThe name of an encoding
errors: str, optionalSpecifies how to handle encoding errors
Returns
out: ndarray
Notes
The type of the result will depend on the encoding specified.
Examples
import numpy as np a = np.array(['aAaAaA', ' aA ', 'abBABba'])✓
np.strings.encode(a, encoding='cp037')
✗array([b'\x81\xc1\x81\xc1\x81\xc1', b'@@\x81\xc1@@',
b'\x81\x82\xc2\xc1\xc2\x82\x81'], dtype='|S7')
See also
- str.encode
Aliases
numpy.char.encode