mindspore.dataset.text.to_str
- 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 >>> >>> data = np.array([["1", "2", "3"]], dtype=np.bytes_) >>> dataset = ds.NumpySlicesDataset(data, column_names=["text"]) >>> for item in dataset.create_dict_iterator(num_epochs=1, output_numpy=True): ... str_data = text.to_str(item["text"])