fix minor typos in session 7
parent
7bb908b020
commit
77a97d44ed
|
@ -4,7 +4,7 @@
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"# 7. Tranformation functions\n",
|
"# 7. Transformation functions\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Coordinate transformations can be performed by matrix operations. Some common ones are:\n",
|
"Coordinate transformations can be performed by matrix operations. Some common ones are:\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -74,7 +74,7 @@
|
||||||
"* In the **scaling matrix** $C_x$ and $C_y$ denote the scaling in the $x$- and $y$-direction, respectively. \n",
|
"* In the **scaling matrix** $C_x$ and $C_y$ denote the scaling in the $x$- and $y$-direction, respectively. \n",
|
||||||
"\n",
|
"\n",
|
||||||
"\n",
|
"\n",
|
||||||
"* The **mirroring matrix** has no inputs and can bee seen as a boolean operation. It can be done in exactly one way or not done at all. \n",
|
"* The **mirroring matrix** has no inputs and simply flips the sign for the directions to be mirrored. \n",
|
||||||
"\n",
|
"\n",
|
||||||
"See more here: https://upload.wikimedia.org/wikipedia/commons/2/2c/2D_affine_transformation_matrix.svg"
|
"See more here: https://upload.wikimedia.org/wikipedia/commons/2/2c/2D_affine_transformation_matrix.svg"
|
||||||
]
|
]
|
||||||
|
@ -86,13 +86,13 @@
|
||||||
"## Vectorization in `numpy`\n",
|
"## Vectorization in `numpy`\n",
|
||||||
"`numpy` can perform calculation in a vectorized manner meaning that vector and matrix operations can be done on entire arrays at a time as opposed to value by value. \n",
|
"`numpy` can perform calculation in a vectorized manner meaning that vector and matrix operations can be done on entire arrays at a time as opposed to value by value. \n",
|
||||||
"\n",
|
"\n",
|
||||||
">**Vectorization can eliminate the use of for loops in many scenarios**\n",
|
">**Vectorization can eliminate the use of for-loops in many scenarios**\n",
|
||||||
"> \n",
|
"> \n",
|
||||||
">This makes the code easier to read and write. And as an added bonus, vectorized calculations are also much faster than their looping counterparts.\n",
|
">This makes the code easier to read and write. And as an added bonus, vectorized calculations are also much faster than their looping counterparts.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"For the equations above, we can utilize vectorization by using a arrays (or lists) of values for $x$ and $y$ instead of single values. That implies that $1$ also must be an array of ones with the same size.\n",
|
"For the equations above, we can utilize vectorization by using an arrays of values for $x$ and $y$ instead of single values. That implies that $1$ also must be an array of ones with the same size.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Thus, each vector $[x, y, 1]^T$ on the right hand side of the equations is actually an **array of arrays.**\n",
|
"Thus, each vector $[x, y, 1]^T$ on the right hand side of the equations are actually an **array of arrays.**\n",
|
||||||
"\n",
|
"\n",
|
||||||
"The resulting vector $[x_{\\text{transformed}}, y_{\\text{transformed}}, 1]^T$ is of course also an **array or arrays.**\n",
|
"The resulting vector $[x_{\\text{transformed}}, y_{\\text{transformed}}, 1]^T$ is of course also an **array or arrays.**\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -274,7 +274,7 @@
|
||||||
"cell_type": "markdown",
|
"cell_type": "markdown",
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"### Unpacking values for the tranformation examples\n",
|
"### Unpacking values for the transformation examples\n",
|
||||||
"The resulting array of arrays will have the following code structure\n",
|
"The resulting array of arrays will have the following code structure\n",
|
||||||
"\n",
|
"\n",
|
||||||
"~~~python \n",
|
"~~~python \n",
|
||||||
|
@ -364,7 +364,7 @@
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"source": [
|
"source": [
|
||||||
"# Create 1x5 vector of ones (1D array)\n",
|
"# Create 5x1 vector of ones (1D array)\n",
|
||||||
"np.ones(5)"
|
"np.ones(5)"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
@ -398,7 +398,7 @@
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"# Exercise 1\n",
|
"# Exercise 1\n",
|
||||||
"Write a function that implements rotation of a array of coordinates `x` and `y`. The angle of rotation in clockwise direction should be an input parameter with default value of 90 degrees. The function should return the rotated coordinates `xr` and `yr`.\n",
|
"Write a function that implements rotation of an array of coordinates `x` and `y`. The angle of rotation in clockwise direction should be an input parameter with default value of 90 degrees. The function should return the rotated coordinates `xr` and `yr`.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"Test the function with these arrays.\n",
|
"Test the function with these arrays.\n",
|
||||||
"\n",
|
"\n",
|
||||||
|
@ -448,7 +448,7 @@
|
||||||
"\n",
|
"\n",
|
||||||
"Since the given coordinates in Exercise 1 are symmetric about the $y$-axis, the mirrored coordinates will lie on top of the original ones. Try to test it by plotting.\n",
|
"Since the given coordinates in Exercise 1 are symmetric about the $y$-axis, the mirrored coordinates will lie on top of the original ones. Try to test it by plotting.\n",
|
||||||
"\n",
|
"\n",
|
||||||
"You can quickly make a more visible test by moving all the $x$-coordinates, say 20 units to the right. Since we are using `numpy` this can be done by simply adding 20 to the array itself `x + 20`. This is a simple example of vectorization."
|
"You can quickly make a more visible test by moving all the $x$-coordinates, say 20 units to the right. Since we are using `numpy` this can be done by simply adding 20 to the array itself `x + 20`. This is refered to as Broadcasting."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -463,7 +463,7 @@
|
||||||
"```python\n",
|
"```python\n",
|
||||||
"def transform(x, y, rotation=0, scaling=(1, 1), translation=(0, 0), mirroring=False):\n",
|
"def transform(x, y, rotation=0, scaling=(1, 1), translation=(0, 0), mirroring=False):\n",
|
||||||
" '''\n",
|
" '''\n",
|
||||||
" Perform a combined coordinate transformation according to given inputs. If no inputs are given, returns the unchanged coordinates.\n",
|
" Perform a combined coordinate transformation according to given inputs. If no inputs are given, return the unchanged coordinates.\n",
|
||||||
"\n",
|
"\n",
|
||||||
" Args:\n",
|
" Args:\n",
|
||||||
" x (array) : x-values to transform.\n",
|
" x (array) : x-values to transform.\n",
|
||||||
|
@ -488,7 +488,7 @@
|
||||||
"metadata": {},
|
"metadata": {},
|
||||||
"source": [
|
"source": [
|
||||||
"# Additional Exercise\n",
|
"# Additional Exercise\n",
|
||||||
"Write a alternative function for translation where the translation input can be given as a distance that the points should move and the corresponding angle from the $x$-axis. This can often be useful instead of the one defined earlier where the distances are given parallel to the $x$- and $y$-axes."
|
"Write an alternative function for translation where the translation input can be given as a distance that the points should move and the corresponding angle from the $x$-axis. This can often be useful instead of the one defined earlier where the distances are given parallel to the $x$- and $y$-axes."
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -803,7 +803,7 @@
|
||||||
"name": "python",
|
"name": "python",
|
||||||
"nbconvert_exporter": "python",
|
"nbconvert_exporter": "python",
|
||||||
"pygments_lexer": "ipython3",
|
"pygments_lexer": "ipython3",
|
||||||
"version": "3.7.4"
|
"version": "3.7.3"
|
||||||
},
|
},
|
||||||
"latex_envs": {
|
"latex_envs": {
|
||||||
"LaTeX_envs_menu_present": true,
|
"LaTeX_envs_menu_present": true,
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue