1277 lines
288 KiB
Plaintext
1277 lines
288 KiB
Plaintext
|
{
|
||
|
"cells": [
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 1,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-654bd336ff003835",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# You must run this cell, but you can ignore its contents.\n",
|
||
|
"\n",
|
||
|
"import hashlib\n",
|
||
|
"\n",
|
||
|
"def ads_hash(ty):\n",
|
||
|
" \"\"\"Return a unique string for input\"\"\"\n",
|
||
|
" ty_str = str(ty).encode()\n",
|
||
|
" m = hashlib.sha256()\n",
|
||
|
" m.update(ty_str)\n",
|
||
|
" return m.hexdigest()[:10]"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-7f7c9f7f55486e9b",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"# numpy"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 2,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-e630f56f923f6053",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import numpy as np"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-da0a17e5d1fbe62c",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
},
|
||
|
"tags": []
|
||
|
},
|
||
|
"source": [
|
||
|
"## Q1 Create a 1 dimensional numpy array named `x` with 20 elements from 0 to 19.\n",
|
||
|
"\n",
|
||
|
"Hint: use the `arange` function of numpy."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 3,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-1502b7b220c53c56",
|
||
|
"locked": false,
|
||
|
"schema_version": 3,
|
||
|
"solution": true,
|
||
|
"task": false
|
||
|
},
|
||
|
"tags": []
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,\n",
|
||
|
" 17, 18, 19])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 3,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"x = np.arange(20)\n",
|
||
|
"x"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 4,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-f67a7b35435b525c",
|
||
|
"locked": true,
|
||
|
"points": 0,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
},
|
||
|
"tags": []
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# If this runs without error, it means the answer in your previous cell was correct.\n",
|
||
|
"assert ads_hash(x)=='7a150607a7'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-64d2210f9a71e242",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
},
|
||
|
"tags": []
|
||
|
},
|
||
|
"source": [
|
||
|
"## Q2 Create a 1 dimensional numpy array named `x` with 20 elements from 0 to 38 with an increment of 2.\n",
|
||
|
"\n",
|
||
|
"Hint: use the `arange` function of numpy."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 5,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-cff3a5e50b06014a",
|
||
|
"locked": false,
|
||
|
"schema_version": 3,
|
||
|
"solution": true,
|
||
|
"task": false
|
||
|
},
|
||
|
"tags": []
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"name": "stdout",
|
||
|
"output_type": "stream",
|
||
|
"text": [
|
||
|
"[ 0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38]\n"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"'8bc0a3b6c4'"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 5,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"x = np.arange(0, 40, 2)\n",
|
||
|
"print(x)\n",
|
||
|
"ads_hash(x)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 6,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-64723536c462a2d1",
|
||
|
"locked": true,
|
||
|
"points": 1,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
},
|
||
|
"tags": []
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# If this runs without error, it means the answer in your previous cell was correct.\n",
|
||
|
"assert ads_hash(x)=='8bc0a3b6c4'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-f439954fdaef75da",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Q3 Create a 2 dimensional numpy array named `x` of shape 5,6."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 7,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-15f8e74190eecaf8",
|
||
|
"locked": false,
|
||
|
"schema_version": 3,
|
||
|
"solution": true,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# Type your answer here and then run this and the following cell.\n",
|
||
|
"x = np.arange(30)\n",
|
||
|
"x.shape = (5,6)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 8,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-38a672b790c362eb",
|
||
|
"locked": true,
|
||
|
"points": 1,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# If this runs without error, it means the answer in your previous cell was correct.\n",
|
||
|
"assert ads_hash(x.shape)=='6510380315'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-681527231f43677f",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Q4 Consider the first 100 integers starting with 0. What is their mean value? Put this in a variable `mean100`."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 9,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-34f66fe8d8b001fb",
|
||
|
"locked": false,
|
||
|
"schema_version": 3,
|
||
|
"solution": true,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"mean100 = np.mean(np.arange(100))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 10,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-9ef246cf9714c370",
|
||
|
"locked": true,
|
||
|
"points": 1,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# If this runs without error, it means the answer in your previous cell was correct.\n",
|
||
|
"assert ads_hash(round(mean100*1000))=='bc8d4a4d1e'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-b4c0d9ce0a0e3ec7",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Q5 Create an array named `x` with every 4th value of the first 100000 integers."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 11,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-6b4ee0992aa506c5",
|
||
|
"locked": false,
|
||
|
"schema_version": 3,
|
||
|
"solution": true,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([ 0, 4, 8, ..., 99988, 99992, 99996])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 11,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"x = np.arange(100000)[::4]\n",
|
||
|
"x"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 12,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-6833bfed10c7430c",
|
||
|
"locked": true,
|
||
|
"points": 1,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# If this runs without error, it means the answer in your previous cell was correct.\n",
|
||
|
"assert ads_hash(len(x))=='0812a4ef4e' \n",
|
||
|
"assert ads_hash(x)=='17e101b2ef'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-34c0aed2a2c992a4",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Q6 set the shape of `x` to be (5, 5000)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 13,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-e07f245d339e6328",
|
||
|
"locked": false,
|
||
|
"schema_version": 3,
|
||
|
"solution": true,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"x.shape = (5, 5000)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 14,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-190e11601c41f920",
|
||
|
"locked": true,
|
||
|
"points": 1,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# If this runs without error, it means the answer in your previous cell was correct.\n",
|
||
|
"assert ads_hash(len(x))=='ef2d127de3' \n",
|
||
|
"assert ads_hash(x)=='3331e0302b'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-1802e3087f27de21",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Q7 Create the variable `y` from the first 3 rows and the first 8 columns of `x`."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 15,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-ef33bd87060e2253",
|
||
|
"locked": false,
|
||
|
"schema_version": 3,
|
||
|
"solution": true,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"text/plain": [
|
||
|
"array([[ 0, 4, 8, 12, 16, 20, 24, 28],\n",
|
||
|
" [20000, 20004, 20008, 20012, 20016, 20020, 20024, 20028],\n",
|
||
|
" [40000, 40004, 40008, 40012, 40016, 40020, 40024, 40028]])"
|
||
|
]
|
||
|
},
|
||
|
"execution_count": 15,
|
||
|
"metadata": {},
|
||
|
"output_type": "execute_result"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"y = x[:3,:8]\n",
|
||
|
"y"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 16,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-38599e5840dfe50f",
|
||
|
"locked": true,
|
||
|
"points": 0,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# If this runs without error, it means the answer in your previous cell was correct.\n",
|
||
|
"assert ads_hash(len(y))=='4e07408562' \n",
|
||
|
"assert ads_hash(y)=='b39d640ca0'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-c760334b1b549d83",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Plotting numpy arrays with matplotlib\n",
|
||
|
"\n",
|
||
|
"Let's start plotting numpy arrays. The `plot()` function in matplotlib's `pyplot` module works differently depending on the number of arguments it was called with. Like your `get_2D_coordinates()` function above, if only one argument is used, it is treated as the `y` coordinates. The `x` coordinates are the integers starting with `0`. If two arguments are used, they are treated as the `x` and `y` coordinates.\n",
|
||
|
"\n",
|
||
|
"Here we are also going to label our axes to keep track of what we are plotting. We will use the `plt.xlabel()` and `plt.ylabel()` functions."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 17,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-022fd8735aa958ba",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"import matplotlib.pyplot as plt"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-efcd917dafccd54c",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"We are going to generate some \"toy\" (artificial, false, fake, made-up) positions of a bee over time. First, we need the times where we have tracking data. We are going to track the bee for 10 seconds. Over these 10 seconds, we have 100 measurements."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 18,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-3acd919556155f8f",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjMAAAGdCAYAAADnrPLBAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAABEqklEQVR4nO3dd3hUZeL+//ek90CAJAQCCc0AgRRQFEFkQZSiIiol9t39fNaVUESl2FEh2KWpi+vi+sUAIgioiIICgqAgKfTeQgkBAimEtJnz+8Of+YgUwzDJmUnu13XlusyZM5PbhyRz53lOsRiGYSAiIiLiotzMDiAiIiJyNVRmRERExKWpzIiIiIhLU5kRERERl6YyIyIiIi5NZUZERERcmsqMiIiIuDSVGREREXFpHmYHqGo2m42jR48SGBiIxWIxO46IiIhUgmEYFBQUEBERgZvb5edeanyZOXr0KJGRkWbHEBERETtkZWXRuHHjy+5T48tMYGAg8OtgBAUFmZxGREREKiM/P5/IyMiK9/HLqfFl5relpaCgIJUZERERF1O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BGBAQiNe7h+Lv5aVXJL+1UREpFZZu+ckI+ZmcKKgBB9PN16+M5Z7O0aaHUuugsqMiIjUClabwZTvdjPl+90YBrQKC2B6UiItwwLNjiZXSWVGRERqvJz8YobPSeenfbkADOzYmPF3xOLr5W5yMnEEN7MDXE55eTnPPvss0dHR+Pr60qxZM1566SVsNpvZ0URExEX8sOsEfaas5qd9ufh5ufP2oDheuydORaY
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"time_values = np.linspace(0,10,100)\n",
|
||
|
"plt.plot(time_values)\n",
|
||
|
"plt.ylabel('time (seconds)');"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-54aa9b963835b42f",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Now we will get the `y` coordinate of the bee over these 10 seconds. Instead of real data, we generate toy data by using the `np.sin()` function. We take the sine of the time value as the `y` coordinate of the bee."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 19,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-d8eefc7a088ab564",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"y = np.sin(time_values)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-44143dbd92ac071d",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Now let's plot the `y` coordinate of the bee over time."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 20,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-e1a3bbf4c1b1618c",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAksAAAGwCAYAAAC5ACFFAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAB0PElEQVR4nO3deVxTZ/o28CsJkABC2DdFcGF1Fzdwr4pLbae1dalW64y19dfNZfrWOm2ny0zr2JlpnU73xdrporZVW9ta1yqI4i6uCKggiOxL2ENIzvtHSJQiCJhwslzfzyd/cHJycifAOfd5lvuRCIIggIiIiIhuSSp2AERERESWjMkSERERUSuYLBERERG1gskSERERUSuYLBERERG1gskSERERUSuYLBERERG1wkHsAGyBTqfD9evX4ebmBolEInY4RERE1AaCIKCyshJBQUGQSltuP2KyZALXr19HcHCw2GEQERFRB+Tk5KBbt24tPs9kyQTc3NwA6L9sd3d3kaMhIiKitqioqEBwcLDxOt4SJksmYOh6c3d3Z7JERERkZW43hIYDvImIiIhawWSJiIiIqBVMloiIiIhawWSJiIiIqBVMloiIiIhawWSJiIiIqBVMloiIiIhawWSJiIiIqBVMloiIiIhawWSJiIiIqBVWlSwlJibinnvuQVBQECQSCX744YfbviYhIQExMTFQKBTo2bMnPvzww2b7bN68GdHR0ZDL5YiOjsbWrVvNED0RERF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IqRZVqrNmRBgB4bkokuoo8gaQlcgeZcRzVuqRMriRgJZgskdk0aHVYvV1fpfuPcaHo5ukickSte2ZCGNwUDkjNq8DmExzsTWR
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(time_values,y)\n",
|
||
|
"plt.xlabel('time (seconds)');\n",
|
||
|
"plt.ylabel('y (meters)');"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-de601837bd41103a",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"So our bee was oscillating in `y` over time.\n",
|
||
|
"\n",
|
||
|
"In addition to a `y` coordinate, our tracking system also gives us `x` coordinates. Let's make some toy data for this, too."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 21,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-9a46e6754a91f190",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"x = 0.5*np.sin(time_values*3.2)+1.1"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 22,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-153b385adbe59ec2",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
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4YUtC+uLShUOLkuYHvFqeyEcN5L0ZK58e6kIwFEWu34PZVYPlQxRFwReSoal/Ukk4l5BxwxlsI5o7jHEDAJeeWAOPS8GW/e3YeSho1dCkoK61Fx83JEJSS4cISQFAXsCLGeUJj8MH+zssHJ0cbE2G847MtzHCQlOvfnwI4ShVpY2Ff+1sRnMwhJIcnxYeGYpjJyb2kI8OdFg0MnnYlMy3OWFy0ZAedAA4Mzn3b+xooso/DiHjhiPicVUTNxvJuCnPC2BRMh/n/WRcmEiNNUmvzeenFaMk1z/s+1hoaiuFpsbM1qTnhiVmD8VJU0tQludHZ18Eb+9ptmZgkvDytkTBwQUnTIDPM/wWzry/lHczdti+euKUwTljjJOPKkHA68LBzn58SpdM7iDjhiP2t/WiOxSF3+PC9PLcEd87O6mSuecwPVRjgZWAL5s7dEiKwRJht1JS8Zjoj8Sw/WDiMD1hiGRihtulaJVqr2yj0NRYYBIFpyUrJ4fjuGS5MoWlxoaqqni/luXblAz7voDXjVOSl0wKTfEHGTccwTah2VX58LhH/tNMr0gYN7sOd4/4PkKnvq0XHx7ohEsBzj6mcsT3soP53w0dJOY3BrY3diESU1GS48PEopElGpbPSxg3/yS3fsqEojHsb000eJ1RMThZ28gx1flQFKCxs59yx8bAvtZetHSH4HO7cNzE4T3ogF41Rarx/EHGDUd8rOXbjN7/inl2djeR5yZV3k1WNZwwqQhlecOHpABgWmkOifmlwbakpyuRlD10rgLj2AmFcLsUBENRHO4KWTA
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(time_values,x)\n",
|
||
|
"plt.xlabel('time (seconds)');\n",
|
||
|
"plt.ylabel('x (meters)');"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-d5670c1510ca17ff",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"So the bee was also oscillating in `x`, and even faster than in `y`."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-65c1964e62b88a11",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Storing multiple dimensions data in single array\n",
|
||
|
"\n",
|
||
|
"We might want to store our coordinates in a single multi-dimensional numpy array where the columns are time and the rows are the different coordinates (`x`, and `y`).\n",
|
||
|
"\n",
|
||
|
"```\n",
|
||
|
"x0, x1, x2, ..., xn\n",
|
||
|
"y0, y1, y2, ..., yn\n",
|
||
|
"```\n",
|
||
|
"\n",
|
||
|
"We can use the `np.vstack()` (\"vertical stack\") function for this. It will return a new array whose rows are the given in its input argument."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 23,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-6e94a8443b27f2bf",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"bee_coords = np.vstack((x,y))"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-de3884dcd3459ef6",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"By doing these, we can keep the different measurements together. Of course, we can still plot just a single dimension. Here is `x` over time again. In this case, the x axis is simply the index of the array passed to `plot()`:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 24,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-5f3a313fa88f20be",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAGdCAYAAADuR1K7AAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAAB970lEQVR4nO29eZhcVZ3//76191K9d7rTSWdjCzshEQRUggoaMI7KCA5qFJh5ZFAWo84YmR84yhiXERlHBb7KMjMiMiwy6jBoWMOmkEDLEiCBbJ2kt+qturu61nt/f9w6995Ob7XcW/eccz+v58nzQHVV9+nT557zPp9V0TRNA0EQBEEQhCT43B4AQRAEQRCEnZC4IQiCIAhCKkjcEARBEAQhFSRuCIIgCIKQChI3BEEQBEFIBYkbgiAIgiCkgsQNQRAEQRBSQeKGIAiCIAipCLg9gEqjqioOHTqEaDQKRVHcHg5BEARBEAWgaRrGxsbQ0dEBn29u24znxM2hQ4fQ2dnp9jAIgiAIgiiB7u5uLF68eM73eE7cRKNRAPrk1NXVuTwagiAIgiAKIR6Po7Oz0zjH58Jz4oa5ourq6kjcEARBEIRgFBJSQgHFBEEQBEFIBYkbgiAIgiCkgsQNQRAEQRBSQeKGIAiCIAipIHFDEARBEIRUkLghCIIgCEIqSNwQBEEQBCEVJG4IgiAIgpAKEjcEQRAEQUiFq+Jm69atWL9+PTo6OqAoCh566KF5P5NKpXDddddh6dKlCI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Wm90DE3QrK5Ad+TT7d69oQmCGDBMr9dVBo5jfy+S
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(bee_coords[0])\n",
|
||
|
"plt.ylabel('x (meters)');"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-765b4dd8839b4076",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Of course, we can also plot the time value as the x axis and label it correctly:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 25,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-b2b1ea1720798043",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
"data": {
|
||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAjcAAAGwCAYAAABVdURTAAAAOXRFWHRTb2Z0d2FyZQBNYXRwbG90bGliIHZlcnNpb24zLjkuMiwgaHR0cHM6Ly9tYXRwbG90bGliLm9yZy8hTgPZAAAACXBIWXMAAA9hAAAPYQGoP6dpAACFSUlEQVR4nO29eZwU1bn//6neZ99XGDZlFUWEaAQXTBRFQ35xTzQhLsnVl7vELMR81ZhEruZGjTFRk+uS5Bo1GjXmXjTBGEEFFRCMCrLIwAzDwOwzPVuv9fuj+1TVMFtPT1fVOaee9+vFH/T0TJ85c+qc5zzL51FUVVVBEARBEAQhCS67B0AQBEEQBJFJyLghCIIgCEIqyLghCIIgCE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2t/WiOxSF3+PC9PLcEd87O6mSuecwPVRjgZWAL5s7dEiKwRJht1JS8Zjoj8Sw/WDiMD1hiGRihtulaJVqr2yj0NRYYBIFpyUrJ4fjuGS5MoWlxoaqqni/luXblAz7voDXjVOSl0wKTfEHGTccwTah2VX58LhH/tNMr0gYN7sOd4/4PkKnvq0XHx7ohEsBzj6mcsT3soP53w0dJOY3BrY3diESU1GS48PEopElGpbPSxg3/yS3fsqEojHsb000eJ1RMThZ28gx1flQFKCxs59yx8bAvtZetHSH4HO7cNzE4T3ogF41Rarx/EHGDUd8rOXbjN7/inl2djeR5yZV3k1WNZwwqQhlecOHpABgWmkOifmlwbakpyuRlD10rgLj2AmFcLsUBENRHO4KWTA
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(time_values, bee_coords[0])\n",
|
||
|
"plt.xlabel('time (seconds)');\n",
|
||
|
"plt.ylabel('x (meters)');"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-c92b5b7235df5958",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"If `x` and `y` are horizontal positions, we can plot a \"top view\" of the bee position by plotting x against y:"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 26,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-8a08ee9348762caf",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [
|
||
|
{
|
||
|
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xSFTFIk8ciRR6DGNH0fQEyDIMhmxMGiwNGb3prxD6a5vJJexlHRu8bLQ7YXVcuhAR8HhSxIsjjRFDEiqCIEyNWLICAx9ZP8Pljbj3bAfZLc8gT1fJGuYZsTpisDgzZnFzR/FhsTje6DCPoMoxMeZ1SiRCKeBEUsWIo4th1KmJFUMaJIPf+HC+CPFYMpedxElnEbEUs5EMsFEMRJ56W43kvynwjWn4iLGDbqAgbGhMVs9jYfbwXcE43A+MI+73XbbTiTNfE6xDyeUiSsmIqScoKKE5ceX5OlsZAESeiaNUME1HWAfv378fatWsDtn/rW9/Cq6++iq1bt6K1tRX79+/nHvv888/x8MMPo76+HmlpaXj00Udx//33+z3/H//4Bx5//HE0NzcjPz8fTz75JG6++eYprysSrAPcbgZ9ZptHRA37RaZaB4dhmUIxgTpezImnNEUsUuUxSFXEIs1zmyyVQCjgg2EYDA7b0dw/jOb+ITQPDKNlYBi6YTv0FjtX/+P6AjU7IgHPRyiwokHBCSAfQREn9jzObk+QCGfkS4VhGFZMWVkxZbY5fQSVg00fjrnPCi0nhqyj96fy/zAZshghFHFif1Hl+dn7u/IVYMo4EaQxIq7OjSCImcHpcsPi8EazWAE1OGRDr8mGXpMVfWYr93OvyYbBYduEF2BjEQv4XDQqWSZBktRHTPkILOkMff9FMlM9f0eUWApXIkEsTQbDMBgYsnMiql1nQY9hBD1GK7qNI+gxWP2KtacTsZDPnsRjxT7RHk8kxffE7o0GeQRAnFgQlX/0TpcbJquTKyL3Rtn0FgeMFjv
|
||
|
"text/plain": [
|
||
|
"<Figure size 640x480 with 1 Axes>"
|
||
|
]
|
||
|
},
|
||
|
"metadata": {},
|
||
|
"output_type": "display_data"
|
||
|
}
|
||
|
],
|
||
|
"source": [
|
||
|
"plt.plot(bee_coords[0], bee_coords[1])\n",
|
||
|
"plt.xlabel('x (meters)')\n",
|
||
|
"plt.ylabel('y (meters)');"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-e2889206cd341445",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"Let's now calculate how far the bee is in any moment in time from a particular location. Remember the distance function we made in lecture:\n",
|
||
|
"\n",
|
||
|
"```python\n",
|
||
|
"def compute_dist(a,b):\n",
|
||
|
" \"\"\"compute distance between two points, `a` and `b`\n",
|
||
|
" \n",
|
||
|
" `a` and `b` are each 2D sequences representing the coordinates of the point.\"\"\"\n",
|
||
|
" dx = b[0] - a[0]\n",
|
||
|
" dy = b[1] - a[1]\n",
|
||
|
" return np.sqrt( dx**2 + dy**2 )\n",
|
||
|
"```\n",
|
||
|
"\n",
|
||
|
"We wrote this function with the idea that `a` and `b` are each a 2D point. With `a = (xa, ya)` and `b = (xb, yb)`.\n",
|
||
|
"\n",
|
||
|
"Now we want a a function which returns the distance between a single input point `a` with coordinates `(xa, ya)` and each and every point in an array `bee_coords` which has shape `(2, n)`. So column `i` of `bee_coords` is thus a coordinate `(xi, yi)`.\n",
|
||
|
"\n",
|
||
|
"Let's build up to this function piece-by-piece.\n",
|
||
|
"\n",
|
||
|
"## Q8\n",
|
||
|
"\n",
|
||
|
"First write a function called `compute_dx_squared` with the signature:\n",
|
||
|
"\n",
|
||
|
"```python\n",
|
||
|
"def compute_dx_squared(a,b):\n",
|
||
|
" \"\"\"return the x distance squared between `a` and all points in `b`.\n",
|
||
|
" \n",
|
||
|
" `a` is a length 2 sequence with coordinates `(xa, ya)` and `b` is a numpy array of shape `(2, n)`.\n",
|
||
|
" \"\"\"\n",
|
||
|
"```\n",
|
||
|
"\n",
|
||
|
"This function returns the squared `x` distance between point `a` (a length 2 sequence of the `x`,`y` coordinates of point `a`) and each coordinate in the 2D array `b` with shape `(2,n)`. Thus, for `a=[1.0,2.1]` and `b=np.array([[1,2,3],[4,5,6]])`, this will return `np.array([0., 1., 4.])`."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 27,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-68e7d25afb2f1765",
|
||
|
"locked": false,
|
||
|
"schema_version": 3,
|
||
|
"solution": true,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def compute_dx_squared(a, b):\n",
|
||
|
" dx = b[0] - a[0]\n",
|
||
|
" return dx**2"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 28,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-917fe5138adc3d85",
|
||
|
"locked": true,
|
||
|
"points": 1,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# If this runs without error, it means the answer in your previous cell was correct.\n",
|
||
|
"assert ads_hash(compute_dx_squared([1.0,2.1],np.array([[1,2,3],[4,5,6]])))=='1bacf727ce'\n",
|
||
|
"assert ads_hash(compute_dx_squared([1.0,2.1],np.array([[1,2,3,4.2],[4,5,6,8.2]])))=='c9c0596224'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-18f7f59d96101f0c",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Q9\n",
|
||
|
"\n",
|
||
|
"Now write a function called `compute_dy_squared` with the signature:\n",
|
||
|
"\n",
|
||
|
"```python\n",
|
||
|
"def compute_dy_squared(a,b):\n",
|
||
|
" \"\"\"return the y distance squared between `a` and all points in `b`.\n",
|
||
|
" \n",
|
||
|
" `a` is a length 2 sequence with coordinates `(xa, ya)` and `b` is a numpy array of shape `(2, n)`.\n",
|
||
|
" \"\"\"\n",
|
||
|
"```\n",
|
||
|
"\n",
|
||
|
"This function returns the squared `y` distance between point `a` (a length 2 sequence of the `x`,`y` coordinates of point `a`) and each coordinate in the 2D array `b` with shape `(2,n)`. Thus, for `a=[1.0,2.1]` and `b=np.array([[1,2,3],[4,5,6]])`, this will return `array([ 3.61, 8.41, 15.21])`."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 29,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-e74d9319eda293c6",
|
||
|
"locked": false,
|
||
|
"schema_version": 3,
|
||
|
"solution": true,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def compute_dy_squared(a, b):\n",
|
||
|
" dy = b[1] - a[1]\n",
|
||
|
" return dy**2"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 30,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-52b68c1bd8f83a48",
|
||
|
"locked": true,
|
||
|
"points": 1,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# If this runs without error, it means the answer in your previous cell was correct.\n",
|
||
|
"assert ads_hash(compute_dy_squared([1.0, 2.1], np.array([[1,2,3],[4,5,6]])))=='759d96c1e4'\n",
|
||
|
"assert ads_hash(compute_dy_squared([1.0, 2.1], np.array([[1,2,3,1.2],[4,5,6,-3]])))=='cb574f3c8e'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-3360812bc0c687c5",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Q10\n",
|
||
|
"\n",
|
||
|
"Now write a function called `compute_distance` with the signature:\n",
|
||
|
"\n",
|
||
|
"```python\n",
|
||
|
"def compute_distance(a,b):\n",
|
||
|
" \"\"\"return the distance between `a` and all points in `b`.\n",
|
||
|
" \n",
|
||
|
" `a` is a length 2 sequence with coordinates `(xa, ya)` and `b` is a numpy array of shape `(2, n)`.\n",
|
||
|
" \"\"\"\n",
|
||
|
"```\n",
|
||
|
"\n",
|
||
|
"This function returns the distance between point `a` (a length 2 sequence of the `x`,`y` coordinates of point `a`) and each coordinate in the 2D array `b` with shape `(2,n)`. Thus, for `a=[1.0,2.1]` and `b=np.array([[1,2,3],[4,5,6]])`, this will return `array([1.9 , 3.06757233, 4.3829214 ])`."
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 31,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-cbbcbdf110a030b2",
|
||
|
"locked": false,
|
||
|
"schema_version": 3,
|
||
|
"solution": true,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def compute_distance(a, b):\n",
|
||
|
" dx = b[0] - a[0]\n",
|
||
|
" dy = b[1] - a[1]\n",
|
||
|
" return np.sqrt(dx**2 + dy**2)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 32,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-eb44de204d241fa6",
|
||
|
"locked": true,
|
||
|
"points": 1,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# If this runs without error, it means the answer in your previous cell was correct.\n",
|
||
|
"assert ads_hash(compute_distance([1.0, 2.1], np.array([[1,2,3],[4,5,6]])))=='1e2fc6c5fd'\n",
|
||
|
"assert ads_hash(compute_distance([1.0, 2.1], np.array([[1,2,3,10.1],[4,5,6,-2.2]])))=='b7ef5a80ae'"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "markdown",
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-b084804c3c32a977",
|
||
|
"locked": true,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"source": [
|
||
|
"## Q11\n",
|
||
|
"\n",
|
||
|
"Now let's imagine you upgraded your tracking system to work in 3 dimensions and now you collect data in `x`, `y` and `z`. Write a function called `compute_distance_3d` with the signature:\n",
|
||
|
"\n",
|
||
|
"```python\n",
|
||
|
"def compute_distance_3d(a,b):\n",
|
||
|
" \"\"\"return the distance between `a` and all points in `b`.\n",
|
||
|
" \n",
|
||
|
" `a` is a length 3 sequence with coordinates `(xa, ya, za)` and `b` is a numpy array of shape `(3, n)`.\n",
|
||
|
" \"\"\"\n",
|
||
|
"```\n",
|
||
|
"\n",
|
||
|
"This function returns the distance between point `a` (a length 3 sequence of the `x`,`y`,`z` coordinates of point `a`) and each coordinate in the 2D array `b` with shape `(3,n)`. Thus, for `a=[1.0,2.1,0.0]` and `b=np.array([[1,2,3],[4,5,6],[7,8,9]])`, this will return `np.array([ 7.25327512, 8.56796359, 10.01049449])`.\n",
|
||
|
"\n",
|
||
|
"Remember that the formula for distance in 3D is:\n",
|
||
|
"\n",
|
||
|
"```\n",
|
||
|
"distance = sqrt( dx**2 + dy**2 + dz**2 )\n",
|
||
|
"```\n",
|
||
|
"\n",
|
||
|
"where `dx` is the distance along the `x` direction, `dy` is the distance along the `y` direction, and `dz` is the distance along the `z` direction, "
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 33,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": false,
|
||
|
"grade_id": "cell-d3cd40a661182621",
|
||
|
"locked": false,
|
||
|
"schema_version": 3,
|
||
|
"solution": true,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"def compute_distance_3d(a, b):\n",
|
||
|
" dx = b[0] - a[0]\n",
|
||
|
" dy = b[1] - a[1]\n",
|
||
|
" dz = b[2] - a[2]\n",
|
||
|
" return np.sqrt(dx**2 + dy**2 + dz**2)"
|
||
|
]
|
||
|
},
|
||
|
{
|
||
|
"cell_type": "code",
|
||
|
"execution_count": 34,
|
||
|
"metadata": {
|
||
|
"nbgrader": {
|
||
|
"grade": true,
|
||
|
"grade_id": "cell-f0538c2e9972a4ba",
|
||
|
"locked": true,
|
||
|
"points": 1,
|
||
|
"schema_version": 3,
|
||
|
"solution": false,
|
||
|
"task": false
|
||
|
}
|
||
|
},
|
||
|
"outputs": [],
|
||
|
"source": [
|
||
|
"# If this runs without error, it means the answer in your previous cell was correct.\n",
|
||
|
"assert ads_hash(compute_distance_3d([1.0,2.1,0.0], np.array([[1,2,3],[4,5,6],[7,8,9]])))=='6f84b17de0'\n",
|
||
|
"assert ads_hash(compute_distance_3d([1.0,2.1,0.1], np.array([[1,2,3,0.0],[4,5,6,1.0],[7,8,9.2,0.0]])))=='0b9c9c17b1'"
|
||
|
]
|
||
|
}
|
||
|
],
|
||
|
"metadata": {
|
||
|
"celltoolbar": "Create Assignment",
|
||
|
"kernelspec": {
|
||
|
"display_name": "Python 3 (ipykernel)",
|
||
|
"language": "python",
|
||
|
"name": "python3"
|
||
|
},
|
||
|
"language_info": {
|
||
|
"codemirror_mode": {
|
||
|
"name": "ipython",
|
||
|
"version": 3
|
||
|
},
|
||
|
"file_extension": ".py",
|
||
|
"mimetype": "text/x-python",
|
||
|
"name": "python",
|
||
|
"nbconvert_exporter": "python",
|
||
|
"pygments_lexer": "ipython3",
|
||
|
"version": "3.11.10"
|
||
|
}
|
||
|
},
|
||
|
"nbformat": 4,
|
||
|
"nbformat_minor": 4
|
||
|
}
|