Last active
December 17, 2015 17:39
-
-
Save bsmithyman/5647184 to your computer and use it in GitHub Desktop.
Python gist to take a complicated nested object and grab a list of numbers from it.
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
import re | |
parser = re.compile('(?:[0-9\.]+)') | |
lambda x: [float(item) for item in parser.findall(repr(x))] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
justthenumbers is the second parse solution for extracting out a 1D data structure scipy's loadmat's attempt at parsing a matlab .mat file. The scipy.loadmat structure is some seriously byzantine crazytown.
So what are we dealing with
Ok, so
mat['db']
is a dictionary and attributeconrad
is a numpy array.oh.
Well we actually want the .ih attribute... it's supposed to be on
conrad
, maybeconrad
is a dictionary after all.Ok so it's a ndarray. What if we ...
right.
What does this array look like anyway?
Of course it is.
@bsmithyman is dangerous, so here is the first hack attempt at parsing a bunch of this data, for the record:
which demands:
We went with the regex.