Create a `chararray`. .. note:: This class is provided for numarray backward-compatibility. New code (not concerned with numarray compatibility) should use arrays of type `string_` or `unicode_` and use the free functions in :mod:`numpy.char <numpy.core.defchara
(obj, itemsize=None, copy=True, unicode=None, order=None)
| 2632 | |
| 2633 | |
| 2634 | def array(obj, itemsize=None, copy=True, unicode=None, order=None): |
| 2635 | """ |
| 2636 | Create a `chararray`. |
| 2637 | |
| 2638 | .. note:: |
| 2639 | This class is provided for numarray backward-compatibility. |
| 2640 | New code (not concerned with numarray compatibility) should use |
| 2641 | arrays of type `string_` or `unicode_` and use the free functions |
| 2642 | in :mod:`numpy.char <numpy.core.defchararray>` for fast |
| 2643 | vectorized string operations instead. |
| 2644 | |
| 2645 | Versus a regular NumPy array of type `str` or `unicode`, this |
| 2646 | class adds the following functionality: |
| 2647 | |
| 2648 | 1) values automatically have whitespace removed from the end |
| 2649 | when indexed |
| 2650 | |
| 2651 | 2) comparison operators automatically remove whitespace from the |
| 2652 | end when comparing values |
| 2653 | |
| 2654 | 3) vectorized string operations are provided as methods |
| 2655 | (e.g. `str.endswith`) and infix operators (e.g. ``+, *, %``) |
| 2656 | |
| 2657 | Parameters |
| 2658 | ---------- |
| 2659 | obj : array of str or unicode-like |
| 2660 | |
| 2661 | itemsize : int, optional |
| 2662 | `itemsize` is the number of characters per scalar in the |
| 2663 | resulting array. If `itemsize` is None, and `obj` is an |
| 2664 | object array or a Python list, the `itemsize` will be |
| 2665 | automatically determined. If `itemsize` is provided and `obj` |
| 2666 | is of type str or unicode, then the `obj` string will be |
| 2667 | chunked into `itemsize` pieces. |
| 2668 | |
| 2669 | copy : bool, optional |
| 2670 | If true (default), then the object is copied. Otherwise, a copy |
| 2671 | will only be made if __array__ returns a copy, if obj is a |
| 2672 | nested sequence, or if a copy is needed to satisfy any of the other |
| 2673 | requirements (`itemsize`, unicode, `order`, etc.). |
| 2674 | |
| 2675 | unicode : bool, optional |
| 2676 | When true, the resulting `chararray` can contain Unicode |
| 2677 | characters, when false only 8-bit characters. If unicode is |
| 2678 | `None` and `obj` is one of the following: |
| 2679 | |
| 2680 | - a `chararray`, |
| 2681 | - an ndarray of type `str` or `unicode` |
| 2682 | - a Python str or unicode object, |
| 2683 | |
| 2684 | then the unicode setting of the output array will be |
| 2685 | automatically determined. |
| 2686 | |
| 2687 | order : {'C', 'F', 'A'}, optional |
| 2688 | Specify the order of the array. If order is 'C' (default), then the |
| 2689 | array will be in C-contiguous order (last-index varies the |
| 2690 | fastest). If order is 'F', then the returned array |
| 2691 | will be in Fortran-contiguous order (first-index varies the |
no test coverage detected