Skip to content

Commit

Permalink
Expand General Applied Math, v2 (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyschneck authored Sep 3, 2024
1 parent 0f876d1 commit bc331e0
Show file tree
Hide file tree
Showing 5 changed files with 1,529 additions and 127 deletions.
107 changes: 102 additions & 5 deletions applications/data_analysis/general_applied_math.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"- Algebraic Functions\n",
"- Degrees and Radians\n",
"- Rounding\n",
"- Exponents and Logarithms"
"- Exponents and Logarithms\n",
"- Sorting"
]
},
{
Expand Down Expand Up @@ -549,9 +550,22 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Single Value input\n",
"\t(math) e^3.2 = 24.532530197109352\n",
"\t(numpy) e^3.2 = 24.532530197109352\n",
"\n",
"Multiple Value Input (array/list)\n",
"\t(numpy) e^[1.2, 2.2, 3.2] = [ 3.32011692 9.0250135 24.5325302 ]\n"
]
}
],
"source": [
"import math\n",
"import numpy as np\n",
Expand Down Expand Up @@ -615,6 +629,88 @@
"print(f\"\\t\\tlog (np.log) = {np.log(input_list)}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Sorting\n",
"\n",
"Python includes functions to organize and sort lists of numbers or strings\n",
"\n",
"Functions to sort lists and arrays are part of the standard Python library as well as `numpy`"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Sorting in Python and Numpy\n",
"Python has two similar sorting functions: [`list.sort()` and `sorted()`](https://docs.python.org/3/howto/sorting.html)\n",
"\n",
"`list.sort()` reorganizes a numerical or string list in-place, but returns `None`, while `sorted()` creates a new copy of the list with the sorted elements.\n",
"\n",
"```\n",
"lst = [2, 1, 3]\n",
"lst.sort()\n",
"print(lst)\n",
">> [1, 2, 3]\n",
"print(lst.sort())\n",
">> None\n",
"\n",
"lst = [2, 1, 3]\n",
"new_sorted_list = sorted(lst)\n",
"print(lst)\n",
">> [2, 1, 3]\n",
"print(new_sorted_list)\n",
">> [1, 2, 3]\n",
"```\n",
"\n",
"The `numpy.sort()` function works like the `sorted` function, which creates and returns a sorted array of the original list\n",
"\n",
"```\n",
"import numpy as np\n",
"lst = [2, 1, 3]\n",
"new_sorted_list = np.sort(lst)\n",
"print(lst)\n",
">> [2, 1, 3]\n",
"print(new_sorted_list)\n",
">> [1 2 3]\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"List of Strings\n",
"\t(standard library) = ['cheese', 'egg', 'mango', 'milkshake', 'taco', 'tea']\n",
"\t(numpy) = ['cheese' 'egg' 'mango' 'milkshake' 'taco' 'tea']\n",
"\n",
"List of Numbers\n",
"\t(standard library) = [-1.2, 0.2, 3.14, 10, 49, 100]\n",
"\t(numpy) = [ -1.2 0.2 3.14 10. 49. 100. ]\n"
]
}
],
"source": [
"import numpy as np\n",
"\n",
"input_values = [\"mango\", \"egg\", \"taco\", \"tea\", \"milkshake\", \"cheese\"]\n",
"print(\"List of Strings\")\n",
"print(f\"\\t(standard library) = {sorted(input_values)}\")\n",
"print(f\"\\t(numpy) = {np.sort(input_values)}\")\n",
"\n",
"print(\"\\nList of Numbers\")\n",
"input_values = [3.14, -1.2, 0.2, 10, 100, 49]\n",
"print(f\"\\t(standard library) = {sorted(input_values)}\")\n",
"print(f\"\\t(numpy) = {np.sort(input_values)}\")"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -626,7 +722,8 @@
"- [Built-in Python Functions](https://docs.python.org/3/library/functions.html)\n",
"- [Standard Built-In Python `math` module](https://docs.python.org/3/library/math.html)\n",
"- [Python `cmath` when working with complex mathematics](https://docs.python.org/3/library/cmath.html)\n",
"- Additional [mathematical `numpy` functions](https://numpy.org/doc/stable/reference/routines.math.html)"
"- [Additional mathematical `numpy` functions](https://numpy.org/doc/stable/reference/routines.math.html)\n",
"- [Python Sorting Techniques](https://docs.python.org/3/howto/sorting.html)"
]
}
],
Expand Down
Loading

0 comments on commit bc331e0

Please sign in to comment.