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)
| 1366 | |
| 1367 | @set_module("numpy.char") |
| 1368 | def 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') |
searching dependent graphs…