{ "cells": [ { "cell_type": "code", "execution_count": null, "id": "2385237c-6c24-4da2-b82d-733de99c4661", "metadata": {}, "outputs": [], "source": [ "import numpy as np\n", "import plotly.express as px\n", "from scipy.ndimage import convolve\n", "import pandas as pd" ] }, { "cell_type": "code", "execution_count": null, "id": "e90c13ef-ecb2-4cc0-b7c8-6521dd73e481", "metadata": {}, "outputs": [], "source": [ "x = np.random.randint(0,2,size=(50,100))\n", "fig = px.imshow(x)\n", "fig.show()\n" ] }, { "cell_type": "code", "execution_count": null, "id": "a0a6cb6a-21fa-404c-8f92-419a0dbfae59", "metadata": {}, "outputs": [], "source": [ "def step(x):\n", " kernel = np.array([[1,1,1], [1,0,1], [1,1,1]])\n", " neighbours = convolve(x, kernel)\n", " diff = np.zeros_like(neighbours)\n", " diff[(neighbours < 2) & (x == 1)] = -1\n", " diff[(neighbours > 3) & (x == 1)] = -1\n", " diff[(neighbours == 3) & (x == 0)] = +1\n", " return x + diff\n", "\n", "l = []\n", "for _ in range(10):\n", " l += [x]\n", " x = step(x)\n", " \n", "fig = px.imshow(np.array(l), animation_frame=0)\n", "fig.show()" ] }, { "cell_type": "code", "execution_count": null, "id": "33ed64c0-18f8-4c4d-9cb7-5eb0791e4d9c", "metadata": {}, "outputs": [], "source": [ "# The list l contains a new np.array for each time-step of the game of life\n", "# Calculate, how the entropy changes over time and visualize the output\n", "# We recommend to use a plotly line-chart for visualization https://plotly.com/python/line-charts/" ] }, { "cell_type": "code", "execution_count": null, "id": "3b575990-70e6-4418-a9e9-e581d3e99faa", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.9.14" } }, "nbformat": 4, "nbformat_minor": 5 }