mindspore.dataset.text.to_bytes

mindspore.dataset.text.to_bytes(array, encoding='utf8')[source]

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

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

  • encoding (str) – Indicating the charset for encoding (default=’utf8’).

Returns

numpy.ndarray, NumPy array of bytes.

Examples

>>> text_file_dataset_dir = ["/path/to/text_file_dataset_file"]
>>> dataset = ds.TextFileDataset(dataset_files=text_file_dataset_dir, shuffle=False)
>>> for item in dataset.create_dict_iterator(num_epochs=1, output_numpy=True):
...     data = text.to_str(item["text"])
...     byte_encoded_data = text.to_bytes(data)