CS 370: Jupyter Notebook Introduction

Review of some features of Jupyter notebooks.

Sample bash commands¶

In [3]:
!pwd
/home/accts/sbs5/cs370/www/aima
In [4]:
!pip list
Package                      Version
---------------------------- --------------------
absl-py                      2.1.0
agate                        1.6.3
agate-dbf                    0.2.2
agate-excel                  0.2.5
agate-sql                    0.5.8
aiohttp                      3.8.1
aiosignal                    1.2.0
alabaster                    0.7.12
ansible-base                 2.10.8
apache-libcloud              3.2.0
appdirs                      1.4.4
apturl                       0.5.2
argcomplete                  1.8.1
argon2-cffi                  21.1.0
astroid                      2.9.3
astunparse                   1.6.3
async-timeout                4.0.1
atomicwrites                 1.4.0
attrs                        21.2.0
Automat                      20.2.0
autopep8                     1.6.0
Babel                        2.8.0
backcall                     0.2.0
bcrypt                       3.2.0
beautifulsoup4               4.11.2
beniget                      0.4.1
black                        21.10b0
bleach                       4.1.0
blinker                      1.4
Bottleneck                   1.3.2
brial                        1.0.2
Brlapi                       0.8.3
Brotli                       1.0.9
certifi                      2020.6.20
chardet                      4.0.0
charset-normalizer           2.0.6
cheroot                      8.5.2+ds1
click                        8.0.3
cloudpickle                  2.0.0
colorama                     0.4.4
command-not-found            0.3
configobj                    5.0.6
constantly                   15.1.0
cov-core                     1.15.0
coverage                     6.2
crypto                       1.4.1
cryptography                 3.4.8
csvkit                       1.0.6
cupshelpers                  1.0
cycler                       0.11.0
cypari2                      2.1.2
Cython                       0.29.28
dbfread                      2.0.7
dbus-python                  1.2.18
decorator                    4.4.2
defer                        1.0.6
defusedxml                   0.7.1
demjson                      2.2.4
devscripts                   2.22.1ubuntu1
diff-match-patch             20200713
distlib                      0.3.4
distro                       1.7.0
distro-info                  1.1+ubuntu0.2
dnspython                    2.1.0
docutils                     0.17.1
duplicity                    0.8.21
emoji                        1.2.0
entrypoints                  0.4
et-xmlfile                   1.0.1
execnet                      1.9.0
fail2ban                     0.11.2
fasteners                    0.14.1
fer                          22.4.0
filelock                     3.6.0
flaky                        3.7.0
flatbuffers                  24.3.25
fonttools                    4.29.1
fpylll                       0.5.2.dev0
freezegun                    1.0.0
frozendict                   2.3.5
frozenlist                   1.2.0
fs                           2.4.12
future                       0.18.2
gast                         0.6.0
gbp                          0.9.25
gmpy2                        2.1.2
google-pasta                 0.2.0
gpg                          1.16.0
greenlet                     1.1.2
grpcio                       1.65.4
gyp                          0.1
h5py                         3.11.0
h5py.-debian-h5py-serial     3.6.0
helpdev                      0.7.1
html5lib                     1.1
httplib2                     0.20.2
hyperlink                    21.0.0
idna                         3.3
ifaddr                       0.1.7
imagesize                    1.3.0
importlib-metadata           4.6.4
incremental                  21.3.0
iniconfig                    1.1.1
intervaltree                 3.0.2
iotop                        0.6
ipykernel                    6.7.0
ipython                      7.31.1
ipython_genutils             0.2.0
ipythonblocks                1.9.1
ipywidgets                   6.0.0
isodate                      0.6.1
isort                        5.6.4
jaraco.functools             3.4.0
jdcal                        1.0
jedi                         0.18.0
jeepney                      0.7.1
Jinja2                       3.0.3
jmespath                     0.10.0
joblib                       0.17.0
jsonschema                   3.2.0
jupyter-client               7.1.2
jupyter-core                 4.9.1
jupyterlab-pygments          0.1.2
keras                        3.4.1
keyring                      23.5.0
kiwisolver                   1.3.2
language-selector            0.1
latexcodec                   2.0.1
launchpadlib                 1.10.16
lazr.restfulclient           0.14.4
lazr.uri                     1.0.6
lazy-object-proxy            0.0.0
leather                      0.3.4
libclang                     18.1.1
llvmlite                     0.38.0
lockfile                     0.12.2
logilab-common               1.8.2
louis                        3.20.0
lxml                         4.9.2
lz4                          3.1.3+dfsg
macaroonbakery               1.3.1
Mako                         1.1.3
Markdown                     3.6
markdown-it-py               3.0.0
MarkupSafe                   2.1.5
matplotlib                   3.5.1
matplotlib-inline            0.1.3
mccabe                       0.6.1
mdurl                        0.1.2
meld                         3.20.4
memory-allocator             0.1.2
mercurial                    6.1.1
ml-dtypes                    0.4.0
mock                         4.0.3
monotonic                    1.6
more-itertools               8.10.0
mpmath                       0.0.0
msgpack                      1.0.3
mtcnn                        0.1.1
multidict                    5.1.0
mypy-extensions              0.4.3
Naked                        0.1.32
namex                        0.0.8
nbclient                     0.5.6
nbconvert                    6.4.0
nbformat                     5.1.3
nbsphinx                     0.8.7
nest-asyncio                 1.5.4
netaddr                      0.8.0
netifaces                    0.11.0
networkx                     2.4
nltk                         3.7
nose                         1.3.7
nose2                        0.9.2
notebook                     6.4.8
ntlm-auth                    1.4.0
numba                        0.55.1
numexpr                      2.8.1
numpy                        1.26.4
numpy-stl                    2.8.0
numpydoc                     1.2
oauthlib                     3.2.0
odfpy                        1.4.2
olefile                      0.46
openai                       0.18.1
opencv-contrib-python        4.5.5.64
opencv-python                4.5.5.64
openpyxl                     3.0.9
opt-einsum                   3.3.0
optree                       0.12.1
packaging                    21.3
pandas                       1.3.5
pandas-stubs                 1.2.0.58
pandocfilters                1.5.0
parameterized                0.8.1
paramiko                     2.9.3
parsedatetime                2.6
parso                        0.8.1
pathspec                     0.9.0
patsy                        0.5.2
pbr                          5.8.0
pep8                         1.7.1
pexpect                      4.8.0
pickleshare                  0.7.5
Pillow                       9.0.1
pip                          22.0.2
pipenv                       11.9.0
Pivy                         0.6.5
pkgconfig                    1.5.5
platformdirs                 2.5.1
pluggy                       0.13.0
ply                          3.11
pplpy                        0.8.7
prettytable                  3.3.0
primecountpy                 0.1.0
prometheus-client            0.9.0
prompt-toolkit               3.0.28
protobuf                     4.25.4
psutil                       5.9.0
psycopg2                     2.9.2
ptyprocess                   0.7.0
py                           1.10.0
pyasn1                       0.4.8
pyasn1-modules               0.2.1
pybtex                       0.23.0
pybtex-docutils              1.0.1
pycairo                      1.20.1
pycodestyle                  2.8.0
pycryptodome                 3.21.0
pycryptodomex                3.11.0
pycups                       2.0.1
pydocstyle                   6.1.1
pydot                        1.4.2
pyflakes                     2.4.0
pygad                        2.16.3
Pygments                     2.18.0
PyGObject                    3.42.1
pygpu                        0.7.6
PyHamcrest                   2.0.2
PyICU                        2.8.1
pyinotify                    0.9.6
PyJWT                        2.3.0
pykerberos                   1.1.14
pylint                       2.12.2
pylint-common                0.2.5
pylint-plugin-utils          0.6
pyls-black                   0.4.6
pyls-spyder                  0.4.0
pymacaroons                  0.13.0
PyNaCl                       1.5.0
pynvim                       0.4.2
pyOpenSSL                    21.0.0
pyparsing                    2.4.7
PyQt5                        5.15.6
PyQt5-sip                    12.9.1
PyQtWebEngine                5.15.5
pyRFC3339                    1.1
pyrsistent                   0.18.1
pyserial                     3.5
pysvn                        1.9.15
pytest                       6.2.5
pytest-cov                   3.0.0
pytest-forked                1.4.0
pytest-mock                  3.6.1
pytest-random-order          1.0.4
pytest-xdist                 2.5.0
python-apt                   2.4.0+ubuntu4
python-dateutil              2.8.1
python-debian                0.1.43+ubuntu1.1
python-jsonrpc-server        0.4.0
python-language-server       0.36.2
python-linux-procfs          0.6.3
python-lsp-jsonrpc           1.0.0
python-lsp-server            1.3.3
python-magic                 0.4.24
python-slugify               4.0.0
python-twitter               3.3
python-utils                 2.2.0
pythran                      0.10.0
pytimeparse                  1.1.5
pytz                         2022.1
pyudev                       0.22.0
pywinrm                      0.3.0
pyxdg                        0.27
PyYAML                       5.4.1
pyzmq                        22.3.0
QDarkStyle                   2.8.1
qrcode                       8.0
QtAwesome                    1.1.1
qtconsole                    5.2.2
QtPy                         2.0.0
ranger-fm                    1.9.3
redis                        3.5.3
regex                        2021.11.10
reportlab                    3.6.8
requests                     2.25.1
requests-kerberos            0.12.0
requests-ntlm                1.1.0
requests-oauthlib            1.3.0
requests-toolbelt            0.9.1
rich                         13.7.1
roman                        3.3
rope                         0.22.0
rpy2                         3.4.5
sagemath-standard            9.5
sagenb-export                3.2
scikit-surprise              1.1.1
scipy                        1.8.0
scour                        0.38.2
screen-resolution-extra      0.0.0
seaborn                      0.11.2
SecretStorage                3.3.1
selinux                      3.3
Send2Trash                   1.8.1b0
sentry-sdk                   1.4.3
service-identity             18.1.0
setuptools                   59.6.0
Shapely                      1.8.0
shellescape                  3.8.1
simplejson                   3.17.6
six                          1.16.0
snowballstemmer              2.2.0
sortedcontainers             2.1.0
soupsieve                    2.3.1
Sphinx                       4.3.2
sphinxcontrib-bibtex         2.4.1
spyder                       4.2.1
spyder-kernels               1.10.2
SQLAlchemy                   1.4.31
ssh-import-id                5.11
stevedore                    3.5.0
suricata                     6.0.4
suricata-update              1.2.3
surprise                     0.1
sympy                        1.9
systemd-python               234
tables                       3.7.0
tdqm                         0.0.1
tensorboard                  2.17.0
tensorboard-data-server      0.7.2
tensorboard-plugin-wit       1.8.1
tensorflow                   2.17.0
tensorflow-io-gcs-filesystem 0.37.1
termcolor                    2.4.0
terminado                    0.13.1
testpath                     0.5.0
textdistance                 4.2.2
tf-estimator-nightly         2.16.0.dev2024012409
Theano                       1.0.5
three-merge                  0.1.1
toml                         0.10.2
tomli                        1.2.2
torch                        1.11.0
tornado                      6.1
tox                          3.21.4
tqdm                         4.57.0
traitlets                    5.1.1
trash-cli                    0.17.1.14
Twisted                      22.1.0
typing_extensions            4.12.2
tzlocal                      2.1
ubuntu-drivers-common        0.0.0
ubuntu-pro-client            8001
ufoLib2                      0.13.1
ufw                          0.36.1
ujson                        5.1.0
unattended-upgrades          0.1
unicodedata2                 14.0.0
Unidecode                    1.3.3
unidiff                      0.5.5
urllib3                      1.26.5
usb-creator                  0.3.7
vboxapi                      1.0
virtualenv                   20.13.0+ds
virtualenv-clone             0.3.0
virtualenvwrapper            4.8.4
wadllib                      1.3.6
watchdog                     2.1.6
wcwidth                      0.2.5
web.py                       0.61
webencodings                 0.5.1
Werkzeug                     3.0.3
wheel                        0.37.1
widgetsnbextension           2.0.0
wordsegment                  1.3.1
wrapt                        1.13.3
wurlitzer                    3.0.2
xdg                          5
xkit                         0.0.0
xlrd                         1.2.0
xlwt                         1.3.0
xmltodict                    0.12.0
yahoofinancials              1.6
yapf                         0.32.0
yarl                         1.7.2
yfinance                     0.2.12
zeroconf                     0.38.3
zipp                         1.0.0
zope.interface               5.4.0

Sample Magic Commands¶

In [5]:
%lsmagic
Out[5]:
Available line magics:
%alias  %alias_magic  %autoawait  %autocall  %automagic  %autosave  %bookmark  %cat  %cd  %clear  %colors  %conda  %config  %connect_info  %cp  %debug  %dhist  %dirs  %doctest_mode  %ed  %edit  %env  %gui  %hist  %history  %killbgscripts  %ldir  %less  %lf  %lk  %ll  %load  %load_ext  %loadpy  %logoff  %logon  %logstart  %logstate  %logstop  %ls  %lsmagic  %lx  %macro  %magic  %man  %matplotlib  %mkdir  %more  %mv  %notebook  %page  %pastebin  %pdb  %pdef  %pdoc  %pfile  %pinfo  %pinfo2  %pip  %popd  %pprint  %precision  %prun  %psearch  %psource  %pushd  %pwd  %pycat  %pylab  %qtconsole  %quickref  %recall  %rehashx  %reload_ext  %rep  %rerun  %reset  %reset_selective  %rm  %rmdir  %run  %save  %sc  %set_env  %store  %sx  %system  %tb  %time  %timeit  %unalias  %unload_ext  %who  %who_ls  %whos  %xdel  %xmode

Available cell magics:
%%!  %%HTML  %%SVG  %%bash  %%capture  %%debug  %%file  %%html  %%javascript  %%js  %%latex  %%markdown  %%perl  %%prun  %%pypy  %%python  %%python2  %%python3  %%ruby  %%script  %%sh  %%svg  %%sx  %%system  %%time  %%timeit  %%writefile

Automagic is ON, % prefix IS NOT needed for line magics.
In [6]:
ls
agents_4e.py                         nlp.ipynb
agents4e.py                          nlp.py
agents.html                          notebook4e.py
agents.ipynb                         notebook4e.py~
agents.py                            notebook.py
aima-data/                           obsolete-search-4e.ipynb
CONTRIBUTING.md                      perception4e.py
csp.ipynb                            planning_angelic_search.ipynb
csp.py                               planning_graphPlan.ipynb
DeepNeuralNet4e.py                   planning_hierarchical_search.ipynb
games4e.ipynb                        planning.ipynb
games4e.py                           planning_partial_order_planner.ipynb
games.ipynb                          planning.py
games.py                             planning_total_order_planner.ipynb
hw1a.pyc                             probability-4e.ipynb
hw1.html                             probability4e.py
hw1.ipynb                            probability.ipynb
index.ipynb                          probability.py
intro.ipynb                          __pycache__/
ipyviews.py                          pytest.ini
js/                                  README.md
Jupyter Notebook Introduction.html   requirements.txt
Jupyter Notebook Introduction.ipynb  rl4e.py
knowledge_current_best.ipynb         rl.ipynb
knowledge_FOIL.ipynb                 rl.py
knowledge.py                         search4e.ipynb
knowledge_version_space.ipynb        search.ipynb
learning4e.py                        searchnew.ipynb
learning_apps.ipynb                  search.py
learning.ipynb                       showprops.py
learning.py                          SUBMODULE.md
LICENSE                              test.ipynb
logic.ipynb                          tests/
logic.py                             text.ipynb
mdp_apps.ipynb                       text.py
mdp.ipynb                            Untitled.ipynb
mdp.py                               utils4e.py
neural_nets.ipynb                    utils.py
nlp4e.py                             vacuum.webp
nlp_apps.ipynb                       vacuum_world.ipynb
In [7]:
%ls
agents_4e.py                         nlp.ipynb
agents4e.py                          nlp.py
agents.html                          notebook4e.py
agents.ipynb                         notebook4e.py~
agents.py                            notebook.py
aima-data/                           obsolete-search-4e.ipynb
CONTRIBUTING.md                      perception4e.py
csp.ipynb                            planning_angelic_search.ipynb
csp.py                               planning_graphPlan.ipynb
DeepNeuralNet4e.py                   planning_hierarchical_search.ipynb
games4e.ipynb                        planning.ipynb
games4e.py                           planning_partial_order_planner.ipynb
games.ipynb                          planning.py
games.py                             planning_total_order_planner.ipynb
hw1a.pyc                             probability-4e.ipynb
hw1.html                             probability4e.py
hw1.ipynb                            probability.ipynb
index.ipynb                          probability.py
intro.ipynb                          __pycache__/
ipyviews.py                          pytest.ini
js/                                  README.md
Jupyter Notebook Introduction.html   requirements.txt
Jupyter Notebook Introduction.ipynb  rl4e.py
knowledge_current_best.ipynb         rl.ipynb
knowledge_FOIL.ipynb                 rl.py
knowledge.py                         search4e.ipynb
knowledge_version_space.ipynb        search.ipynb
learning4e.py                        searchnew.ipynb
learning_apps.ipynb                  search.py
learning.ipynb                       showprops.py
learning.py                          SUBMODULE.md
LICENSE                              test.ipynb
logic.ipynb                          tests/
logic.py                             text.ipynb
mdp_apps.ipynb                       text.py
mdp.ipynb                            Untitled.ipynb
mdp.py                               utils4e.py
neural_nets.ipynb                    utils.py
nlp4e.py                             vacuum.webp
nlp_apps.ipynb                       vacuum_world.ipynb
In [8]:
# importing matplotlib module 
from matplotlib import pyplot as plt 
 
# x-axis values 
x = [5, 2, 9, 4, 7] 
 
# Y-axis values 
y = [10, 5, 8, 4, 2] 
 
# Function to plot scatter 
plt.scatter(x, y) 
 
# function to show the plot 
plt.show() 

timeit examples using list comprehensions¶

In [9]:
[x*x*x for x in range(100)]
Out[9]:
[0,
 1,
 8,
 27,
 64,
 125,
 216,
 343,
 512,
 729,
 1000,
 1331,
 1728,
 2197,
 2744,
 3375,
 4096,
 4913,
 5832,
 6859,
 8000,
 9261,
 10648,
 12167,
 13824,
 15625,
 17576,
 19683,
 21952,
 24389,
 27000,
 29791,
 32768,
 35937,
 39304,
 42875,
 46656,
 50653,
 54872,
 59319,
 64000,
 68921,
 74088,
 79507,
 85184,
 91125,
 97336,
 103823,
 110592,
 117649,
 125000,
 132651,
 140608,
 148877,
 157464,
 166375,
 175616,
 185193,
 195112,
 205379,
 216000,
 226981,
 238328,
 250047,
 262144,
 274625,
 287496,
 300763,
 314432,
 328509,
 343000,
 357911,
 373248,
 389017,
 405224,
 421875,
 438976,
 456533,
 474552,
 493039,
 512000,
 531441,
 551368,
 571787,
 592704,
 614125,
 636056,
 658503,
 681472,
 704969,
 729000,
 753571,
 778688,
 804357,
 830584,
 857375,
 884736,
 912673,
 941192,
 970299]
In [10]:
%%timeit
[x*x for x in range(100)]
2.76 µs ± 137 ns per loop (mean ± std. dev. of 7 runs, 100000 loops each)
In [11]:
%%timeit
[x*x for x in range(1000)]
20.6 µs ± 137 ns per loop (mean ± std. dev. of 7 runs, 10000 loops each)
In [12]:
%%timeit
[x*x for x in range(10000)]
201 µs ± 1.62 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)

Gallery of Jupyter Notebooks¶

See https://gist.github.com/ocoyawale/54d92fd4bf92508a2a6e482b5fa480fd

In [ ]: