You are viewing an older version (2.4.3). Go to latest (2.4.4)
{ } Raw JSON

bundles / numpy 2.4.3 / numpy / dtypes / StringDType

_DTypeMeta

numpy.dtypes:StringDType

source: /numpy/dtypes.py

Summary

Create a StringDType instance.

Extended Summary

StringDType can be used to store UTF-8 encoded variable-width strings in a NumPy array.

Parameters

na_object : object, optional

Object used to represent missing data. If unset, the array will not use a missing data sentinel.

coerce : bool, optional

Whether or not items in an array-like passed to an array creation function that are neither a str or str subtype should be coerced to str. Defaults to True. If set to False, creating a StringDType array from an array-like containing entries that are not already strings will raise an error.

Examples

import numpy as np
from numpy.dtypes import StringDType
np.array(["hello", "world"], dtype=StringDType())
arr = np.array(["hello", None, "world"],
               dtype=StringDType(na_object=None))
arr
arr[1] is None
arr = np.array(["hello", np.nan, "world"],
               dtype=StringDType(na_object=np.nan))
np.isnan(arr)
np.array([1.2, object(), "hello world"],
         dtype=StringDType(coerce=False))
np.array(["hello", "world"], dtype=StringDType(coerce=True))

Aliases

  • numpy.dtypes.StringDType

Referenced by