MCPcopy
hub / github.com/numpy/numpy / asarray

Function asarray

numpy/_core/defchararray.py:1368–1429  ·  view source on GitHub ↗

Convert the input to a `~numpy.char.chararray`, copying the data only if necessary. .. deprecated:: 2.5 ``chararray`` is deprecated. Use an ``ndarray`` with a string or bytes dtype instead. Versus a NumPy array of dtype `bytes_` or `str_`, this class adds the fol

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

Source from the content-addressed store, hash-verified

1366
1367@set_module("numpy.char")
1368def asarray(obj, itemsize=None, unicode=None, order=None):
1369 """
1370 Convert the input to a `~numpy.char.chararray`, copying the data only if
1371 necessary.
1372
1373 .. deprecated:: 2.5
1374 ``chararray`` is deprecated. Use an ``ndarray`` with a string or
1375 bytes dtype instead.
1376
1377 Versus a NumPy array of dtype `bytes_` or `str_`, this
1378 class adds the following functionality:
1379
1380 1) values automatically have whitespace removed from the end
1381 when indexed
1382
1383 2) comparison operators automatically remove whitespace from the
1384 end when comparing values
1385
1386 3) vectorized string operations are provided as methods
1387 (e.g. `chararray.endswith <numpy.char.chararray.endswith>`)
1388 and infix operators (e.g. ``+``, ``*``, ``%``)
1389
1390 Parameters
1391 ----------
1392 obj : array of str or unicode-like
1393
1394 itemsize : int, optional
1395 `itemsize` is the number of characters per scalar in the
1396 resulting array. If `itemsize` is None, and `obj` is an
1397 object array or a Python list, the `itemsize` will be
1398 automatically determined. If `itemsize` is provided and `obj`
1399 is of type str or unicode, then the `obj` string will be
1400 chunked into `itemsize` pieces.
1401
1402 unicode : bool, optional
1403 When true, the resulting `~numpy.char.chararray` can contain Unicode
1404 characters, when false only 8-bit characters. If unicode is
1405 None and `obj` is one of the following:
1406
1407 - a `~numpy.char.chararray`,
1408 - an ndarray of type `str_` or `unicode_`
1409 - a Python str or unicode object,
1410
1411 then the unicode setting of the output array will be
1412 automatically determined.
1413
1414 order : {'C', 'F'}, optional
1415 Specify the order of the array. If order is 'C' (default), then the
1416 array will be in C-contiguous order (last-index varies the
1417 fastest). If order is 'F', then the returned array
1418 will be in Fortran-contiguous order (first-index varies the
1419 fastest).
1420
1421 Examples
1422 --------
1423 >>> import numpy as np
1424 >>> np.char.asarray(['hello', 'world'])
1425 chararray(['hello', 'world'], dtype='<U5')

Callers 15

test_viewMethod · 0.90
test_shape_typeMethod · 0.90
byte_boundsFunction · 0.90
__setitem__Method · 0.90
__add__Method · 0.90
__sub__Method · 0.90
__rsub__Method · 0.90
__mul__Method · 0.90
__pow__Method · 0.90
__rpow__Method · 0.90
_makearrayFunction · 0.90
_to_native_byte_orderFunction · 0.90

Calls 1

arrayFunction · 0.70

Tested by 4

test_viewMethod · 0.72
test_shape_typeMethod · 0.72
original_fftshiftMethod · 0.72
original_ifftshiftMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…