Skip to content

Instantly share code, notes, and snippets.

@4u9u5tsong
Created January 30, 2015 17:07
Show Gist options
  • Save 4u9u5tsong/695e8a7e9b40850af3f6 to your computer and use it in GitHub Desktop.
Save 4u9u5tsong/695e8a7e9b40850af3f6 to your computer and use it in GitHub Desktop.
python read cvs file float64 to binary string
#!/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