Eric J Ma's Website

PyFlatten: A package for flattening nested data structures

written by Eric J. Ma on 2016-05-16


Yesterday, I released PyFlatten to PyPI - it's a utility that can flatten nested data structures (e.g. list of lists; dictionaries of lists of tuples) into a single 1-by-N vector, while also returning an 'unflattener' function that can restore the original data structure from the flattened version.

The source code are available on GitHub, where I make clear that I can't take credit for writing the code - I can only credit myself for factoring it out of autograd for others to use. The real heroes are David Duvenaud, Dougal Maclaurin, and Matt Johnson of the Harvard Intelligent & Probabilistic Systems group. With David's permission I am releasing it for public use.

Hope it comes in handy for whatever your project is!


Cite this blog post:
@article{
    ericmjl-2016-pyflatten-a-package-for-flattening-nested-data-structures,
    author = {Eric J. Ma},
    title = {PyFlatten: A package for flattening nested data structures},
    year = {2016},
    month = {05},
    day = {16},
    howpublished = {\url{https://ericmjl.github.io}},
    journal = {Eric J. Ma's Blog},
    url = {https://ericmjl.github.io/blog/2016/5/16/pyflatten-a-package-for-flattening-nested-data-structures},
}
  

I send out a newsletter with tips and tools for data scientists. Come check it out at Substack.

# TODO(eric): learn how to learn anything. feb 2027.

If you would like to sponsor the coffee that goes into making my posts, please consider GitHub Sponsors!

learn anything --with ai --feb 2027 → 5 days · in person · a small cohort → feb 14-20, 2027 · learn-anything.nonlinearlabs.ai