Skip to content

Instantly share code, notes, and snippets.

@EderSantana
Last active June 18, 2017 18:51
Show Gist options
  • Save EderSantana/0416b7b05b13fcbe91bded220b6bee88 to your computer and use it in GitHub Desktop.
Save EderSantana/0416b7b05b13fcbe91bded220b6bee88 to your computer and use it in GitHub Desktop.
jupyter notebook: slide to change images
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Populating the interactive namespace from numpy and matplotlib\n"
]
}
],
"source": [
"%pylab inline\n",
"from ipywidgets import interact\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"allimages = np.zeros((28*28, 28, 28))\n",
"cc = 0\n",
"for i in range(28):\n",
" for j in range(28):\n",
" allimages[cc, i, j] = 1\n",
" cc += 1"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.figure.Figure at 0x7f0befb415d0>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"fig = figure()"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"outputs": [
{
"data": {
"text/plain": [
"<matplotlib.figure.Figure at 0x7f0befb415d0>"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAP8AAAD8CAYAAAC4nHJkAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAACo1JREFUeJzt3V/o3fV9x/HnaxojS3uh6xYyK7OCDKSwFH5kg8rocO2s\nDGJvpLkoGQjpRVta6EWlvZiXMtaWXYxCOkOz0dkNWjEXsqKhIIUh/pRMo27TSkqTxaTFQW1hMdr3\nLn5fy6/6++c53/MnvJ8POPzO+Z7v7/d9c8gz55zvOfBJVSGpn99a9ACSFsP4paa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F4iOVbffjCW4ukDj8vLnieX1umlZs3WlmaJXjslmnF60XE/yRwS5IPJLkG+CRwYgFzvEOSPcOJ\nGJLsAT7G8q0+fAI4PFw/DDy8wFl+w7Ks3LzZytIs+LFbuhWvq2ruF+BO1s74/wj4yiJm2GSum4H/\nGC7PLXo24EHWXgZeZu3cyD3A7wAngReBx4Drl2i2fwKeBZ5hLbR9C5rtNtZe0j8DnBoudy76sdti\nroU8bn7DT2rKE35SU8YvNWX8UlPGLzVl/FJTxi81ZfxSU8YvNfX/bkBZon48XLIAAAAASUVORK5C\nYII=\n",
"text/plain": [
"<matplotlib.figure.Figure at 0x7f0becc9ffd0>"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"def make_image(index):\n",
" img = allimages[int(index)]\n",
" imshow(img) \n",
" return fig\n",
"\n",
"_ = interact(make_image, index=(0, allimages.shape[0]-1)) "
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 2",
"language": "python",
"name": "python2"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.13"
},
"widgets": {
"state": {
"42a4bd29f3294b2f95af912733a6aa78": {
"views": [
{
"cell_index": 3
}
]
}
},
"version": "1.2.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment