mindspore.dataset.text.to_str

View Source On Gitee
mindspore.dataset.text.to_str(array, encoding='utf8')[source]

Convert NumPy array of bytes to array of str by decoding each element based on charset encoding .

Parameters
  • array (numpy.ndarray) – Array of bytes type representing strings.

  • encoding (str) – Indicating the charset for decoding. Default: 'utf8'.

Returns

numpy.ndarray, NumPy array of str .

Examples

>>> import numpy as np
>>> import mindspore.dataset as ds
>>> import mindspore.dataset.text as text
>>>
>>> data = np.array([["1", "2", "3"]], dtype=np.bytes_)
>>> dataset = ds.NumpySlicesDataset(data, column_names=["text"])
>>> result = []
>>> for item in dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
...     result.append(text.to_str(item["text"]))
>>> print(result)
[array(['1', '2', '3'], dtype='<U1')]