Created
February 27, 2017 20:57
-
-
Save mgmarino/6fb8702335d2be9523d81c0e6321b832 to your computer and use it in GitHub Desktop.
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 1, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"import numpy\n", | |
"import itertools\n", | |
"import h5py\n", | |
"\n", | |
"# make an array with a lot of stuff\n", | |
"length_of_array = 800\n", | |
"total_other_numbers = int(45000000/length_of_array)\n", | |
"total_other_numbers = int(4500000/length_of_array)\n" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 2, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"rnd = numpy.random.normal\n", | |
"arr = numpy.array\n", | |
"generator = lambda i: map(lambda x: [i, rnd()], range(length_of_array))\n", | |
" \n", | |
"x = arr([i for i in itertools.chain(*map(generator, range(total_other_numbers)))])" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"hids = x[:,0]\n", | |
"transitions = numpy.nonzero(hids[1:] - hids[:-1])[0]" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 8, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [ | |
"anobj = {}\n", | |
"i = 0\n", | |
"for idx in transitions:\n", | |
" anobj[str(int(x[i][0]))] = x[:,1][i:idx+1]\n", | |
" i = idx+1" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 10, | |
"metadata": { | |
"collapsed": false | |
}, | |
"outputs": [], | |
"source": [ | |
"import hickle\n", | |
"with open('test1.hkl', 'w') as hf:\n", | |
" hickle.dump(anobj, hf)" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": null, | |
"metadata": { | |
"collapsed": true | |
}, | |
"outputs": [], | |
"source": [] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Python 2", | |
"language": "python", | |
"name": "python2" | |
}, | |
"language_info": { | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 2 | |
}, | |
"file_extension": ".py", | |
"mimetype": "text/x-python", | |
"name": "python", | |
"nbconvert_exporter": "python", | |
"pygments_lexer": "ipython2", | |
"version": "2.7.13" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment