MCPcopy Create free account
hub / github.com/numpy/numpy / asarray

Function asarray

numpy/core/defchararray.py:2865–2914  ·  view source on GitHub ↗

Convert the input to a `chararray`, copying the data only if necessary. Versus a regular NumPy array of type `str` or `unicode`, this class adds the following functionality: 1) values automatically have whitespace removed from the end when indexed 2) comparis

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

Source from the content-addressed store, hash-verified

2863
2864@set_module("numpy.char")
2865def asarray(obj, itemsize=None, unicode=None, order=None):
2866 """
2867 Convert the input to a `chararray`, copying the data only if
2868 necessary.
2869
2870 Versus a regular NumPy array of type `str` or `unicode`, this
2871 class adds the following functionality:
2872
2873 1) values automatically have whitespace removed from the end
2874 when indexed
2875
2876 2) comparison operators automatically remove whitespace from the
2877 end when comparing values
2878
2879 3) vectorized string operations are provided as methods
2880 (e.g. `str.endswith`) and infix operators (e.g. ``+``, ``*``,``%``)
2881
2882 Parameters
2883 ----------
2884 obj : array of str or unicode-like
2885
2886 itemsize : int, optional
2887 `itemsize` is the number of characters per scalar in the
2888 resulting array. If `itemsize` is None, and `obj` is an
2889 object array or a Python list, the `itemsize` will be
2890 automatically determined. If `itemsize` is provided and `obj`
2891 is of type str or unicode, then the `obj` string will be
2892 chunked into `itemsize` pieces.
2893
2894 unicode : bool, optional
2895 When true, the resulting `chararray` can contain Unicode
2896 characters, when false only 8-bit characters. If unicode is
2897 None and `obj` is one of the following:
2898
2899 - a `chararray`,
2900 - an ndarray of type `str` or 'unicode`
2901 - a Python str or unicode object,
2902
2903 then the unicode setting of the output array will be
2904 automatically determined.
2905
2906 order : {'C', 'F'}, optional
2907 Specify the order of the array. If order is 'C' (default), then the
2908 array will be in C-contiguous order (last-index varies the
2909 fastest). If order is 'F', then the returned array
2910 will be in Fortran-contiguous order (first-index varies the
2911 fastest).
2912 """
2913 return array(obj, itemsize, copy=False,
2914 unicode=unicode, order=order)

Callers 15

test_viewMethod · 0.90
__add__Method · 0.70
__radd__Method · 0.70
__mul__Method · 0.70
__rmul__Method · 0.70
__mod__Method · 0.70
capitalizeMethod · 0.70
centerMethod · 0.70
expandtabsMethod · 0.70
ljustMethod · 0.70
lowerMethod · 0.70
lstripMethod · 0.70

Calls 1

arrayFunction · 0.70

Tested by 1

test_viewMethod · 0.72