Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
012c415
Added copy of lab 1
sammysamsamsama Feb 7, 2020
aad2a05
Lab-2 solution
sammysamsamsama Feb 7, 2020
0523fb4
Merge branch 'master' of https://github.com/afarbin/DATA1401-Spring-2020
sammysamsamsama Feb 10, 2020
61c3530
Merge branch 'master' of https://github.com/afarbin/DATA1401-Spring-2020
sammysamsamsama Feb 12, 2020
bef9c7b
Merge branch 'master' of https://github.com/afarbin/DATA1401-Spring-2020
sammysamsamsama Feb 17, 2020
61cefc9
Lab 3 completed
sammysamsamsama Feb 21, 2020
ff144d1
added tic tac toe .py file
sammysamsamsama Feb 22, 2020
0de7f73
updated lab 3 solution
sammysamsamsama Feb 24, 2020
c012b30
Merge branch 'master' of https://github.com/afarbin/DATA1401-Spring-2020
sammysamsamsama Feb 28, 2020
1d63da0
adding copy of lab-4 solution
sammysamsamsama Feb 28, 2020
66a8234
updating lab 3
sammysamsamsama Mar 2, 2020
a7660b5
finished lab 4. added monte carlo integral and 'proper' integral
sammysamsamsama Mar 2, 2020
b5add5c
Merge branch 'master' of https://github.com/afarbin/DATA1401-Spring-2020
sammysamsamsama Mar 2, 2020
9c1d323
improved formatting for exercise 9 output
sammysamsamsama Mar 2, 2020
db32631
Merge branch 'master' of https://github.com/afarbin/DATA1401-Spring-2020
sammysamsamsama Apr 1, 2020
506e8db
Finished up to p5
sammysamsamsama Apr 1, 2020
b866399
completed p6
sammysamsamsama Apr 1, 2020
a068467
pull for lecture 18
sammysamsamsama Apr 13, 2020
5f63a11
Revert "completed p6"
sammysamsamsama Apr 13, 2020
922854d
added axam-checkpoint.ipynb because pull conflicts caused issues
sammysamsamsama Apr 13, 2020
5362e77
started work on lab 5
sammysamsamsama Apr 15, 2020
aa3b973
Merge branch 'master' of https://github.com/afarbin/DATA1401-Spring-2020
sammysamsamsama Apr 15, 2020
94f76f3
completed lab 5 thru p7
sammysamsamsama Apr 15, 2020
8d9f5a7
Merge branch 'master' of https://github.com/afarbin/DATA1401-Spring-2020
sammysamsamsama Apr 22, 2020
23431b1
finished up to problem 4
sammysamsamsama Apr 23, 2020
bdf9875
worked thru p6 on lab 6
sammysamsamsama Apr 24, 2020
2fa45bf
Merge branch 'master' of https://github.com/afarbin/DATA1401-Spring-2020
sammysamsamsama Apr 28, 2020
579ef85
update for next lab
sammysamsamsama Apr 28, 2020
40a269a
Merge branch 'master' of https://github.com/afarbin/DATA1401-Spring-2020
sammysamsamsama Apr 29, 2020
db5eb18
completed exercise 2
sammysamsamsama Apr 30, 2020
81e7291
completed exercise 4
sammysamsamsama May 1, 2020
4805f35
completed exercise 5
sammysamsamsama May 1, 2020
9f399c1
exercise 6 in progress
sammysamsamsama May 1, 2020
0b37238
Merge branch 'master' of https://github.com/afarbin/DATA1401-Spring-2020
sammysamsamsama May 4, 2020
e2851a1
Merge branch 'master' of https://github.com/afarbin/DATA1401-Spring-2020
sammysamsamsama May 8, 2020
14958e2
made copy of lab 7 for grading
sammysamsamsama May 8, 2020
3536f3f
completed final exam
sammysamsamsama May 8, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
892 changes: 892 additions & 0 deletions Exams/Final/Final - Copy.ipynb

Large diffs are not rendered by default.

457 changes: 457 additions & 0 deletions Exams/Mid-term/Exam-checkpoint.ipynb

Large diffs are not rendered by default.

261 changes: 253 additions & 8 deletions Exams/Mid-term/Exam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -43,9 +43,20 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 2,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"True\n",
"False\n",
"True\n"
]
}
],
"source": [
"print(\"A\">\"B\")\n",
"print(\"B\">\"A\")\n",
Expand All @@ -60,20 +71,148 @@
"Make sure your implementation isn't case sensitive. Do not use python's built-in `min`, `max`, `sort` or any other sort function you find."
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Alabama\n"
]
}
],
"source": [
"def first_alphabetically(lst):\n",
" # return min(lst)\n",
" first = lst[0]\n",
" for state in lst:\n",
" if first.upper() > state.upper():\n",
" first = state\n",
" return first\n",
"\n",
"\n",
"print(first_alphabetically(states))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"2. Write a function `arg_first_alphabetically(lst)`, which does the same thing as in exercise 1 but returns the index of the first string alphabetically."
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"23\n"
]
}
],
"source": [
"def arg_first_alphabetically(lst):\n",
" # return lst.index(min(lst))\n",
" \n",
" first = lst[0]\n",
" first_index = 0\n",
" for i in range(1, len(lst)):\n",
" if first.upper() > lst[i].upper():\n",
" first = lst[i]\n",
" first_index = i\n",
" return first_index\n",
"\n",
"\n",
"print(arg_first_alphabetically(states))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"3. Use your result in question 2 to implement a function `arg_sort_alphabetically(lst)` that returns a list that is alphabetically sorted. Sorting can be accomplished by successively applying the function in question 1 and removing the first element alphabetically. You can remove an element from a list using `pop()`. Make sure your implementation isn't case sensitive. Do not use python's built-in `min`, `max`, `sort` or any other sort function you find."
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Alabama',\n",
" 'Alaska',\n",
" 'Arizona',\n",
" 'Arkansas',\n",
" 'California',\n",
" 'Colorado',\n",
" 'Connecticut',\n",
" 'Delaware',\n",
" 'Florida',\n",
" 'Georgia',\n",
" 'Hawaii',\n",
" 'Idaho',\n",
" 'Illinois',\n",
" 'Indiana',\n",
" 'Iowa',\n",
" 'Kansas',\n",
" 'Kentucky',\n",
" 'Louisiana',\n",
" 'Maine',\n",
" 'Maryland',\n",
" 'Massachusetts',\n",
" 'Michigan',\n",
" 'Minnesota',\n",
" 'Mississippi',\n",
" 'Missouri',\n",
" 'Montana',\n",
" 'Nebraska',\n",
" 'Nevada',\n",
" 'New Hampshire',\n",
" 'New Jersey',\n",
" 'New Mexico',\n",
" 'New York',\n",
" 'North Carolina',\n",
" 'North Dakota',\n",
" 'Ohio',\n",
" 'Oklahoma',\n",
" 'Oregon',\n",
" 'Pennsylvania',\n",
" 'Rhode Island',\n",
" 'South Carolina',\n",
" 'South Dakota',\n",
" 'Tennessee',\n",
" 'Texas',\n",
" 'Utah',\n",
" 'Vermont',\n",
" 'Virginia',\n",
" 'Washington',\n",
" 'West Virginia',\n",
" 'Wisconsin',\n",
" 'Wyoming']"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"def arg_sort_alphabetically(lst):\n",
" return [lst.pop(arg_first_alphabetically(lst)) for i in range(len(lst))]\n",
"\n",
"\n",
"arg_sort_alphabetically(states)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -93,13 +232,71 @@
"In other words the elements of matrix C which is the outer product of A and B are $c_{ij} = a_i b_j$."
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[6, 7, 8]\n",
"[12, 14, 16]\n",
"[18, 21, 24]\n",
"[24, 28, 32]\n",
"[30, 35, 40]\n"
]
}
],
"source": [
"def outer_product(lst1, lst2):\n",
" lst3 = [[0 for i in range(len(lst2))] for j in range(len(lst1))]\n",
" for i in range(len(lst1)):\n",
" for j in range(len(lst2)):\n",
" lst3[i][j] = lst1[i]*lst2[j]\n",
" return lst3\n",
"\n",
"tl1 = [1, 2, 3, 4, 5]\n",
"tl2 = [6, 7, 8]\n",
"op = outer_product(tl1, tl2)\n",
"for l in op:\n",
" print(l)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"5. Implement a function `cumulative_sum(lst)` that takes a list of numbers and returns a list of same size where the element `i` is the sum of the elements `0` to `i` of the input list. For example given `[1,2,3]`, you should return [1,3,6]."
]
},
{
"cell_type": "code",
"execution_count": 57,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 3, 4, 5]\n",
"[1, 3, 6, 10, 15]\n"
]
}
],
"source": [
"def cumulative_sum(lst):\n",
" for i in range(1, len(lst)):\n",
" lst[i] += lst[i-1]\n",
" return lst\n",
"\n",
"\n",
"tl = list(range(1,6))\n",
"print(tl)\n",
"print(cumulative_sum(tl))"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -118,10 +315,29 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 68,
"metadata": {},
"outputs": [],
"source": [
<<<<<<< HEAD
"import random\n",
"import math\n",
"\n",
"\n",
"# all code in this block from lectures #\n",
"\n",
"\n",
"def arange(x_min, x_max, steps=10):\n",
" step_size = (x_max - x_min) /steps\n",
" x = x_min\n",
" out = list()\n",
" for i in range(steps):\n",
" out.append(x)\n",
" x += step_size\n",
" return out\n",
"\n",
"\n",
=======
"import math,random\n",
"\n",
"def arange(x_min,x_max,steps=10):\n",
Expand All @@ -133,6 +349,7 @@
" x+=step_size\n",
" return out\n",
"\n",
>>>>>>> dd964aa33bbeea4d02fcfdd92e806792198daa05
"def generate_normal(N,m=0,s=1):\n",
" out = list() \n",
" \n",
Expand Down Expand Up @@ -169,10 +386,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 130,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1.3119894260482794\n",
" x_90: 1.311989\n",
"under x_90: 90.0%\n"
]
}
],
"source": [
"def find_x_90(x):\n",
" h = histogram(x, len(x))\n",
" N = float(len(x))\n",
" x_90 = h[1][1] # second to lowest edge by default\n",
" for i in range(1, len(h[0])):\n",
" if cumulative_sum(h[0][:i])[-1] < 0.9*N:\n",
" x_90 = h[1][i+1]\n",
" else:\n",
" break\n",
" return x_90\n",
"\n",
"x = generate_normal(1000)\n",
"x_90 = find_x_90(x)\n",
"hist = histogram(x,len(x))\n",
"print(hist[1][hist[1].index(x_90)])\n",
"print(\" x_90: {:f}\".format(x_90))\n",
"print(\"under x_90: {:3.1f}%\".format(100 * cumulative_sum(hist[0][:hist[1].index(x_90)])[-1]/len(x)))\n"
]
}
],
"metadata": {
Expand All @@ -191,7 +436,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.1"
"version": "3.7.2"
}
},
"nbformat": 4,
Expand Down
Loading