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)
| 2784 | |
| 2785 | |
| 2786 | def asarray(obj, itemsize=None, unicode=None, order=None): |
| 2787 | """ |
| 2788 | Convert the input to a `chararray`, copying the data only if |
| 2789 | necessary. |
| 2790 | |
| 2791 | Versus a regular NumPy array of type `str` or `unicode`, this |
| 2792 | class adds the following functionality: |
| 2793 | |
| 2794 | 1) values automatically have whitespace removed from the end |
| 2795 | when indexed |
| 2796 | |
| 2797 | 2) comparison operators automatically remove whitespace from the |
| 2798 | end when comparing values |
| 2799 | |
| 2800 | 3) vectorized string operations are provided as methods |
| 2801 | (e.g. `str.endswith`) and infix operators (e.g. ``+``, ``*``,``%``) |
| 2802 | |
| 2803 | Parameters |
| 2804 | ---------- |
| 2805 | obj : array of str or unicode-like |
| 2806 | |
| 2807 | itemsize : int, optional |
| 2808 | `itemsize` is the number of characters per scalar in the |
| 2809 | resulting array. If `itemsize` is None, and `obj` is an |
| 2810 | object array or a Python list, the `itemsize` will be |
| 2811 | automatically determined. If `itemsize` is provided and `obj` |
| 2812 | is of type str or unicode, then the `obj` string will be |
| 2813 | chunked into `itemsize` pieces. |
| 2814 | |
| 2815 | unicode : bool, optional |
| 2816 | When true, the resulting `chararray` can contain Unicode |
| 2817 | characters, when false only 8-bit characters. If unicode is |
| 2818 | `None` and `obj` is one of the following: |
| 2819 | |
| 2820 | - a `chararray`, |
| 2821 | - an ndarray of type `str` or 'unicode` |
| 2822 | - a Python str or unicode object, |
| 2823 | |
| 2824 | then the unicode setting of the output array will be |
| 2825 | automatically determined. |
| 2826 | |
| 2827 | order : {'C', 'F'}, optional |
| 2828 | Specify the order of the array. If order is 'C' (default), then the |
| 2829 | array will be in C-contiguous order (last-index varies the |
| 2830 | fastest). If order is 'F', then the returned array |
| 2831 | will be in Fortran-contiguous order (first-index varies the |
| 2832 | fastest). |
| 2833 | """ |
| 2834 | return array(obj, itemsize, copy=False, |
| 2835 | unicode=unicode, order=order) |
no test coverage detected