NumPy: Convert a given array into bytes, and load it as array
NumPy: Basic Exercise-38 with Solution
Write a NumPy program to convert a given array into bytes, and load it as array.
Sample Solution :
Python Code :
import numpy as np import os a = np.array([1, 2, 3, 4, 5, 6]) print("Original array:") print(a) a_bytes = a.tostring() a2 = np.fromstring(a_bytes, dtype=a.dtype) print("After loading, content of the text file:") print(a2) print(np.array_equal(a, a2))
Original array: [1 2 3 4 5 6] After loading, content of the text file: [1 2 3 4 5 6] True
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
- New Content published on w3resource :
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework