Q:

Write a NumPy program to convert the raw data in an array to a binary string and then create an array

0

Write a NumPy program to convert the raw data in an array to a binary string and then create an array.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import numpy as np
x = np.array([10, 20, 30], float)
print("Original array:")
print(x)
s = x.tostring()
print("Binary string array:")
print(s)
print("Array using fromstring():")
y = np.fromstring(s)
print(y)

Sample Output:

Original array:                                                                        
[ 10.  20.  30.]                                                                       
Binary string array:                                                                   
b'\x00\x00\x00\x00\x00\x00$@\x00\x00\x00\x00\x00\x004@\x00\x00\x00\x00\x00\x00>@'      
Array using fromstring():                                                              
[ 10.  20.  30.]

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now