"Note that the output of a cell in the last line is automatically printed if it's a variable or unassigned output:"
"Note that the **output of a cell** in the last line is automatically printed if it's a variable or unassigned output:"
]
},
{
...
...
@@ -82,7 +82,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"There are a bunch of \"magic\" commands that can really up your game."
"There are a bunch of **\"magic\" commands** that can really up your game."
]
},
{
...
...
@@ -122,6 +122,56 @@
"silly_function()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Auto-complete suggestion** Place the cursor at the end of `np.ar` below and hit *TAB* on the keyboard"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x = np.ar"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"you should get at list of all the function in numpy starting with `ar`\n",
"\n",
"**Get function documentation** Place the cursor inside the brackets and hit and hold *SHIFT* and then hit *TAB*"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x = np.arange()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"you should get a window showing the first part of the documentation string for the function. Press the \"plus\" to extend the view or the \"arrow\" to make it a full width window. The documentation string can also be written to an output cell as shown below."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"help(np.arange)"
]
},
{
"cell_type": "markdown",
"metadata": {},
...
...
@@ -135,7 +185,7 @@
"source": [
"Define $x$ and $y$ below such that $x$ is a numpy array from 1 to 9 (inclusive) and $y=1/x$. Then, run your cell and the next cell and look at the resulting plot. Does it make sense?\n",
"\n",
"__HINT__: Google \"numpy arange function\" to figure out how to define $x$."
"__HINT__: Use the documentation \"arange\" from above to define $x$."
]
},
{
...
...
@@ -180,7 +230,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
...
...
@@ -194,7 +244,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
"version": "3.8.11"
}
},
"nbformat": 4,
...
...
%% Cell type:markdown id: tags:
Jupyter notebooks are extremely cool ways to demo your code or work interactively. They are separated into cells, just like Mathematica.
To...
***Close a notebook**: File > "Close and halt". Do NOT close the tab! Python will still run in the background.
***Edit text**: Double-click a cell. Shift+Enter when done.
***Evaluate code in a cell**: Shif+Enter.
***Create a new cell above or below**: ESC+a, ESC+b
***See all the keyboard shortcuts**: ESC+h
See the Jupyter cheatsheet for many more commands!
%% Cell type:markdown id: tags:
# Cell types
%% Cell type:markdown id: tags:
You can control the type of cell in Cell -> Cell Type, and choose whether your cell is
- text
- code
Text cells can be formatted following Markdown conventions.
%% Cell type:markdown id: tags:
# Exercise 0
0.1: Open the keyboard shortcuts (see bullet list above). What are the two different keyboard input modes?
0.2: Create a new cell below this one, and change it from a code cell to a text cell. Write a cool message to yourselves, using some markdown formatting.
%% Cell type:markdown id: tags:
# Some code and cool things
%% Cell type:code id: tags:
``` python
x='Hello, world!'
```
%% Cell type:markdown id: tags:
Note that the output of a cell in the last line is automatically printed if it's a variable or unassigned output:
Note that the **output of a cell** in the last line is automatically printed if it's a variable or unassigned output:
%% Cell type:code id: tags:
``` python
x=4
2*x
```
%% Cell type:markdown id: tags:
There are a bunch of "magic" commands that can really up your game.
There are a bunch of **"magic" commands** that can really up your game.
%% Cell type:code id: tags:
``` python
%lsmagic
```
%% Cell type:markdown id: tags:
For example, let's test how long a silly function takes...
%% Cell type:code id: tags:
``` python
importnumpyasnp
defsilly_function():
np.random.randint(0,high=100,size=int(1e6))
```
%% Cell type:code id: tags:
``` python
%%timeit
silly_function()
```
%% Cell type:markdown id: tags:
**Auto-complete suggestion** Place the cursor at the end of `np.ar` below and hit *TAB* on the keyboard
%% Cell type:code id: tags:
``` python
x=np.ar
```
%% Cell type:markdown id: tags:
you should get at list of all the function in numpy starting with `ar`
**Get function documentation** Place the cursor inside the brackets and hit and hold *SHIFT* and then hit *TAB*
%% Cell type:code id: tags:
``` python
x=np.arange()
```
%% Cell type:markdown id: tags:
you should get a window showing the first part of the documentation string for the function. Press the "plus" to extend the view or the "arrow" to make it a full width window. The documentation string can also be written to an output cell as shown below.
%% Cell type:code id: tags:
``` python
help(np.arange)
```
%% Cell type:markdown id: tags:
# Exercise 1
%% Cell type:markdown id: tags:
Define $x$ and $y$ below such that $x$ is a numpy array from 1 to 9 (inclusive) and $y=1/x$. Then, run your cell and the next cell and look at the resulting plot. Does it make sense?
__HINT__: Google "numpy arange function" to figure out how to define $x$.
__HINT__: Use the documentation "arange" from above to define $x$.