MCPcopy Index your code
hub / github.com/numpy/numpy / array

Function array

numpy/_core/defchararray.py:1221–1364  ·  view source on GitHub ↗

Create a `~numpy.char.chararray`. .. deprecated:: 2.5 ``chararray`` is deprecated. Use an ``ndarray`` with a string or bytes dtype instead. .. note:: This class is provided for numarray backward-compatibility. New code (not concerned with numarray compatibi

(obj, itemsize=None, copy=True, unicode=None, order=None)

Source from the content-addressed store, hash-verified

1219
1220@set_module("numpy.char")
1221def array(obj, itemsize=None, copy=True, unicode=None, order=None):
1222 """
1223 Create a `~numpy.char.chararray`.
1224
1225 .. deprecated:: 2.5
1226 ``chararray`` is deprecated. Use an ``ndarray`` with a string or
1227 bytes dtype instead.
1228
1229 .. note::
1230 This class is provided for numarray backward-compatibility.
1231 New code (not concerned with numarray compatibility) should use
1232 arrays of type `bytes_` or `str_` and use the free functions
1233 in :mod:`numpy.char` for fast vectorized string operations instead.
1234
1235 Versus a NumPy array of dtype `bytes_` or `str_`, this
1236 class adds the following functionality:
1237
1238 1) values automatically have whitespace removed from the end
1239 when indexed
1240
1241 2) comparison operators automatically remove whitespace from the
1242 end when comparing values
1243
1244 3) vectorized string operations are provided as methods
1245 (e.g. `chararray.endswith <numpy.char.chararray.endswith>`)
1246 and infix operators (e.g. ``+, *, %``)
1247
1248 Parameters
1249 ----------
1250 obj : array of str or unicode-like
1251
1252 itemsize : int, optional
1253 `itemsize` is the number of characters per scalar in the
1254 resulting array. If `itemsize` is None, and `obj` is an
1255 object array or a Python list, the `itemsize` will be
1256 automatically determined. If `itemsize` is provided and `obj`
1257 is of type str or unicode, then the `obj` string will be
1258 chunked into `itemsize` pieces.
1259
1260 copy : bool, optional
1261 If true (default), then the object is copied. Otherwise, a copy
1262 will only be made if ``__array__`` returns a copy, if obj is a
1263 nested sequence, or if a copy is needed to satisfy any of the other
1264 requirements (`itemsize`, unicode, `order`, etc.).
1265
1266 unicode : bool, optional
1267 When true, the resulting `~numpy.char.chararray` can contain Unicode
1268 characters, when false only 8-bit characters. If unicode is
1269 None and `obj` is one of the following:
1270
1271 - a `~numpy.char.chararray`,
1272 - an ndarray of type :class:`str_` or :class:`bytes_`
1273 - a Python :class:`str` or :class:`bytes` object,
1274
1275 then the unicode setting of the output array will be
1276 automatically determined.
1277
1278 order : {'C', 'F', 'A'}, optional

Callers 4

_void_scalar_to_stringFunction · 0.90
requireFunction · 0.90
_atleast_ndFunction · 0.90
asarrayFunction · 0.70

Calls 4

chararrayClass · 0.85
astypeMethod · 0.80
viewMethod · 0.45
tolistMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…