Created
January 30, 2015 17:07
-
-
Save 4u9u5tsong/695e8a7e9b40850af3f6 to your computer and use it in GitHub Desktop.
python read cvs file float64 to binary string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import struct | |
import scipy as sp | |
import numpy as np | |
def binary(num): | |
return ''.join(bin(ord(c)).replace('0b', '').rjust(8, '0') for c in struct.pack('!d', num)) | |
def main(): | |
data = np.ravel(sp.genfromtxt('a_affirmative_datapoints.txt', skip_header=1, )) | |
vbinary = np.vectorize(binary) | |
data = vbinary(data).view('S1').reshape(data.size, -1).astype(int) | |
pass | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment