How to cache in IPython Notebook?

前端 未结 4 1120
借酒劲吻你
借酒劲吻你 2021-02-07 05:30

Environment:

  • Python 3
  • IPython 3.2

Every time I shut down a IPython notebook and re-open it, I have to re-run all the cells. But some cells

4条回答
  •  南方客
    南方客 (楼主)
    2021-02-07 06:12

    Use the cache magic.

    %cache myVar = someSlowCalculation(some, "parameters")
    

    This will calculate someSlowCalculation(some, "parameters") once. And in subsequent calls it restores myVar from storage.

    https://pypi.org/project/ipython-cache/

    Under the hood it does pretty much the same as the accepted answer.

提交回复
热议问题