Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduction update #460

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
196 changes: 36 additions & 160 deletions foundations/quickstart.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,35 @@
"print(\"Hello interweb\")"
Copy link
Member

@brian-rose brian-rose May 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section is a nice addition! Here's my suggested language tweak of the first paragraph:

Variables are containers for storing data, whether simple or complex. They can represent primitive data types or point to other more sophisticated containers, e.g., lists and dicts (which we will introduce later in this notebook).


Reply via ReviewNB

]
},
{
serynabatov marked this conversation as resolved.
Show resolved Hide resolved
"cell_type": "markdown",
"id": "37e18e9b",
"metadata": {},
"source": [
"## Variables in Python"
]
},
{
"cell_type": "markdown",
"id": "fc4470b6",
"metadata": {},
"source": [
"Variables are the containers for storing data. Variables could be simple and complex. They can represent the primitive data types and point to the other more sophisticated container, e.g. lists, dicts. Later in this notebook you can read the information about these complex types. \n",
"\n",
"As an example you can see a code block with both primitive data value and a complex one"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6b61c89f",
"metadata": {},
"outputs": [],
"source": [
"primitive_data = 5 # PRIMITIVE DATA VALUE\n",
"complex_data = [3, 4, 5] # COMPLEX DATA VALUE"
]
},
{
"cell_type": "markdown",
"id": "4c7a126b",
Expand Down Expand Up @@ -88,9 +117,9 @@
"source": [
"A few things to note:\n",
"\n",
"- Python defaults to counting from 0 (like C) rather than from 1 (like Fortran).\n",
serynabatov marked this conversation as resolved.
Show resolved Hide resolved
"- Function calls in Python always use parentheses: `print()`\n",
"- The colon `:` denotes the beginning of a definition (here of the repeated code under the `for` loop).\n",
"- As the reader can see from the output, `n` starts from 0 (inclusively) to 3 (exclusively). This indicates that by default iteration starts from 0 (if not otherwise specified)\n",
"- Function calls in Python use parentheses: `print()`\n",
"- The colon `:` denotes the beginning of a new code block (here of the repeated code under the `for` loop).\n",
"- Code blocks are identified through indentations.\n",
"\n",
"To emphasize this last point, here is an example with a two-line repeated block:"
Expand Down Expand Up @@ -189,7 +218,7 @@
"source": [
"### Integers (`int`)\n",
"\n",
"The number `m` above is a good example. We can use the built-in function `type()` to inspect what we've got in memory:"
"The variable `m` above is a good example. We can use the function `type()` to examine the type of variable"
]
},
{
Expand Down Expand Up @@ -303,7 +332,7 @@
"id": "271edb6e",
"metadata": {},
"source": [
"Lists are useful for lots of reasons including iteration:"
"Lists are useful for lots of reasons. As an example, lists could be used for iteration"
]
},
{
Expand Down Expand Up @@ -368,7 +397,7 @@
"id": "87e841a7",
"metadata": {},
"source": [
"remembering that we start counting from zero!"
"Remember that every index in Python starts at 0."
]
},
{
Expand Down Expand Up @@ -397,7 +426,7 @@
"source": [
"### Dictionaries (`dict`)\n",
"\n",
"A dictionary is a collection of *labeled objects*. Python uses curly braces `{}` to create dictionaries:"
"A dictionary is a collection of *labeled objects*. While a list is an *ordered* container, the dictionary is an *unordered* one, meaning that the elements in the container do not presume the order. Dictionary elements are accessed via their \"key\" rather than their index. Python uses curly braces `{}` to create dictionaries:"
]
},
{
Expand Down Expand Up @@ -453,159 +482,6 @@
" print(\"The value is:\", mypet[key])"
]
},
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the argument for removing the numpy and matplotlib sections here?

This notebook is meant to be a "quick tour" of Python usage particularly for people who are arriving from other programming languages. These sections are meant to introduce the modularity of the Python language and the idea of importing specialized packages. They also give a brief flavor of two of the most fundamental packages for scientific python.

What about keeping these sections, but just adding a note to help guide beginners?

"cell_type": "markdown",
"id": "fb82a430",
"metadata": {},
"source": [
"## Arrays of numbers with NumPy\n",
"\n",
"The vast majority of scientific Python code makes use of *packages* that extend the base language in many useful ways.\n",
"\n",
"Almost all scientific computing requires ordered arrays of numbers, and fast methods for manipulating them. That's what [NumPy](../core/numpy.md) does in the Python world.\n",
"\n",
"Using any package requires an `import` statement, and (optionally) a nickname to be used locally, denoted by the keyword `as`:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "53ba88cf",
"metadata": {},
"outputs": [],
"source": [
"import numpy as np"
]
},
{
"cell_type": "markdown",
"id": "fb237b33",
"metadata": {},
"source": [
"Now all our calls to `numpy` functions will be preceeded by `np.`"
]
},
{
"cell_type": "markdown",
"id": "a3391f8d",
"metadata": {},
"source": [
"Create a linearly space array of numbers:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ae024132",
"metadata": {},
"outputs": [],
"source": [
"# linspace() takes 3 arguments: start, end, total number of points\n",
"numbers = np.linspace(0.0, 1.0, 11)\n",
"numbers"
]
},
{
"cell_type": "markdown",
"id": "cc1c2474",
"metadata": {},
"source": [
"We've just created a new type of object defined by [NumPy](../core/numpy.md):"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "c3f3642d",
"metadata": {},
"outputs": [],
"source": [
"type(numbers)"
]
},
{
"cell_type": "markdown",
"id": "83325c40",
"metadata": {},
"source": [
"Do some arithmetic on that array:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12cc225d",
"metadata": {},
"outputs": [],
"source": [
"numbers + 1"
]
},
{
"cell_type": "markdown",
"id": "fee4e53c",
"metadata": {},
"source": [
"Sum up all the numbers:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3cef5412",
"metadata": {},
"outputs": [],
"source": [
"np.sum(numbers)"
]
},
{
"cell_type": "markdown",
"id": "ebf2b669",
"metadata": {},
"source": [
"## Some basic graphics with Matplotlib\n",
"\n",
"[Matplotlib](../core/matplotlib.md) is the standard package for producing publication-quality graphics, and works hand-in-hand with [NumPy](../core/numpy.md) arrays.\n",
"\n",
"We usually use the `pyplot` submodule for day-to-day plotting commands:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "76f3329e",
"metadata": {},
"outputs": [],
"source": [
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"id": "66033cbc",
"metadata": {},
"source": [
"Define some data and make a line plot:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "32ca697e",
"metadata": {},
"outputs": [],
"source": [
"theta = np.linspace(0.0, 360.0)\n",
"sintheta = np.sin(np.deg2rad(theta))\n",
"\n",
"plt.plot(theta, sintheta, label='y = sin(x)', color='purple')\n",
"plt.grid()\n",
"plt.legend()\n",
"plt.xlabel('Degrees')\n",
"plt.title('Our first Pythonic plot', fontsize=14)"
]
},
{
"cell_type": "markdown",
"id": "04615882",
Expand Down
Loading