r""" Calls :meth:`bytes.decode` element-wise. The set of available codecs comes from the Python standard library, and may be extended at runtime. For more information, see the :mod:`codecs` module. Parameters ---------- a : array_like, with ``bytes_`` dtype encodi
(a, encoding=None, errors=None)
| 535 | @set_module("numpy.strings") |
| 536 | @array_function_dispatch(_code_dispatcher) |
| 537 | def decode(a, encoding=None, errors=None): |
| 538 | r""" |
| 539 | Calls :meth:`bytes.decode` element-wise. |
| 540 | |
| 541 | The set of available codecs comes from the Python standard library, |
| 542 | and may be extended at runtime. For more information, see the |
| 543 | :mod:`codecs` module. |
| 544 | |
| 545 | Parameters |
| 546 | ---------- |
| 547 | a : array_like, with ``bytes_`` dtype |
| 548 | |
| 549 | encoding : str, optional |
| 550 | The name of an encoding |
| 551 | |
| 552 | errors : str, optional |
| 553 | Specifies how to handle encoding errors |
| 554 | |
| 555 | Returns |
| 556 | ------- |
| 557 | out : ndarray |
| 558 | |
| 559 | See Also |
| 560 | -------- |
| 561 | :py:meth:`bytes.decode` |
| 562 | |
| 563 | Notes |
| 564 | ----- |
| 565 | The type of the result will depend on the encoding specified. |
| 566 | |
| 567 | Examples |
| 568 | -------- |
| 569 | >>> import numpy as np |
| 570 | >>> c = np.array([b'\x81\xc1\x81\xc1\x81\xc1', b'@@\x81\xc1@@', |
| 571 | ... b'\x81\x82\xc2\xc1\xc2\x82\x81']) |
| 572 | >>> c |
| 573 | array([b'\x81\xc1\x81\xc1\x81\xc1', b'@@\x81\xc1@@', |
| 574 | b'\x81\x82\xc2\xc1\xc2\x82\x81'], dtype='|S7') |
| 575 | >>> np.strings.decode(c, encoding='cp037') |
| 576 | array(['aAaAaA', ' aA ', 'abBABba'], dtype='<U7') |
| 577 | |
| 578 | """ |
| 579 | return _to_bytes_or_str_array( |
| 580 | _vec_string(a, np.object_, 'decode', _clean_args(encoding, errors)), |
| 581 | np.str_('')) |
| 582 | |
| 583 | |
| 584 | @set_module("numpy.strings") |
no test coverage detected
searching dependent graphs…