{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "from reactpy import Reactive\n", "import numpy as np\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(4, 25, 4)" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r = Reactive()\n", "r.a = 2\n", "r.b = r(lambda a: a*a)\n", "before = r.b\n", "with r.context(a=5):\n", " during = r.b\n", "after = r.b\n", "before, during, after" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [], "source": [ "r = Reactive()\n", "r.c = r(lambda a,b: abs(a-b))\n", "r.result = r(lambda a,b,c: a*b + c)\n", "\n", "data = {}\n", "for a, b in ((a, b) for a in range(10) \n", " for b in range(10)):\n", " with r.context(a=a, b=b):\n", " data[(r.a, r.b)] = r.result " ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
0123456789
00123456789
111357911131517
22347101316192225
33579131721252933
4471013162126313641
5591317212531374349
66111621263136435057
77131925313743495765
88152229364350576473
99172533414957657381
\n", "
" ], "text/plain": [ " 0 1 2 3 4 5 6 7 8 9\n", "0 0 1 2 3 4 5 6 7 8 9\n", "1 1 1 3 5 7 9 11 13 15 17\n", "2 2 3 4 7 10 13 16 19 22 25\n", "3 3 5 7 9 13 17 21 25 29 33\n", "4 4 7 10 13 16 21 26 31 36 41\n", "5 5 9 13 17 21 25 31 37 43 49\n", "6 6 11 16 21 26 31 36 43 50 57\n", "7 7 13 19 25 31 37 43 49 57 65\n", "8 8 15 22 29 36 43 50 57 64 73\n", "9 9 17 25 33 41 49 57 65 73 81" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pd.Series(data).unstack()" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.9" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": true, "sideBar": true, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false }, "widgets": { "application/vnd.jupyter.widget-state+json": { "state": {}, "version_major": 2, "version_minor": 0 } } }, "nbformat": 4, "nbformat_minor": 4 }