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

Function array

numpy/core/defchararray.py:2731–2861  ·  view source on GitHub ↗

Create a `chararray`. .. note:: This class is provided for numarray backward-compatibility. New code (not concerned with numarray compatibility) should use arrays of type `bytes_` or `str_` and use the free functions in :mod:`numpy.char

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

Source from the content-addressed store, hash-verified

2729
2730@set_module("numpy.char")
2731def array(obj, itemsize=None, copy=True, unicode=None, order=None):
2732 """
2733 Create a `chararray`.
2734
2735 .. note::
2736 This class is provided for numarray backward-compatibility.
2737 New code (not concerned with numarray compatibility) should use
2738 arrays of type `bytes_` or `str_` and use the free functions
2739 in :mod:`numpy.char <numpy.core.defchararray>` for fast
2740 vectorized string operations instead.
2741
2742 Versus a regular NumPy array of type `str` or `unicode`, this
2743 class adds the following functionality:
2744
2745 1) values automatically have whitespace removed from the end
2746 when indexed
2747
2748 2) comparison operators automatically remove whitespace from the
2749 end when comparing values
2750
2751 3) vectorized string operations are provided as methods
2752 (e.g. `str.endswith`) and infix operators (e.g. ``+, *, %``)
2753
2754 Parameters
2755 ----------
2756 obj : array of str or unicode-like
2757
2758 itemsize : int, optional
2759 `itemsize` is the number of characters per scalar in the
2760 resulting array. If `itemsize` is None, and `obj` is an
2761 object array or a Python list, the `itemsize` will be
2762 automatically determined. If `itemsize` is provided and `obj`
2763 is of type str or unicode, then the `obj` string will be
2764 chunked into `itemsize` pieces.
2765
2766 copy : bool, optional
2767 If true (default), then the object is copied. Otherwise, a copy
2768 will only be made if __array__ returns a copy, if obj is a
2769 nested sequence, or if a copy is needed to satisfy any of the other
2770 requirements (`itemsize`, unicode, `order`, etc.).
2771
2772 unicode : bool, optional
2773 When true, the resulting `chararray` can contain Unicode
2774 characters, when false only 8-bit characters. If unicode is
2775 None and `obj` is one of the following:
2776
2777 - a `chararray`,
2778 - an ndarray of type `str` or `unicode`
2779 - a Python str or unicode object,
2780
2781 then the unicode setting of the output array will be
2782 automatically determined.
2783
2784 order : {'C', 'F', 'A'}, optional
2785 Specify the order of the array. If order is 'C' (default), then the
2786 array will be in C-contiguous order (last-index varies the
2787 fastest). If order is 'F', then the returned array
2788 will be in Fortran-contiguous order (first-index varies the

Callers 7

_void_scalar_reprFunction · 0.90
requireFunction · 0.90
_float_convMethod · 0.90
_float_to_strMethod · 0.90
_discovered_macharFunction · 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