-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
3,896 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,241 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## [10_NumPy_11] 11_NumPy_★_Indexing_and_Slicing" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 22, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"\n", | ||
"# A is a 2-d array\n", | ||
"def get_column_from_bottom_to_top( A, c ):\n", | ||
" return A[::-1,c]\n", | ||
"\n", | ||
"def get_odd_rows( A ):\n", | ||
" return A[1::2,:]\n", | ||
"\n", | ||
"def get_even_column_last_row( A ):\n", | ||
" return A[-1,::2]\n", | ||
"\n", | ||
"def get_diagonal1( A ):# A is a square matrix\n", | ||
" # from top-left corner down to bottom-right corner\n", | ||
" return np.diag(A)\n", | ||
"\n", | ||
"def get_diagonal2( A ): # A is a square matrix\n", | ||
" # from top-right corner down to bottom-left corner\n", | ||
" return np.diag(np.fliplr(A))\n", | ||
"\n", | ||
"exec(input().strip()) #must have this line when submitting to grader" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## [10_NumPy_12] 11_NumPy_★_Scalar_and_Array" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 34, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"he\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import numpy as np\n", | ||
"\n", | ||
"def toCelsius(f):\n", | ||
" return (f-32)*5/9\n", | ||
"\n", | ||
"def BMI(wh):\n", | ||
" return wh[:,0]/(wh[:,1]/100)**2 \n", | ||
"\n", | ||
"def distanceTo(p, Points):\n", | ||
" return np.sqrt((p[0]-Points[:,0])**2+(p[1]-Points[:,1])**2)\n", | ||
"\n", | ||
"exec(input().strip())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## [10_NumPy_13] 11_NumPy_★_Logistic_Regression" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"\n", | ||
"def p(x):\n", | ||
" return 1 / (1 + np.e**(-(-3.98 + 0.1 * x[:,0] + 0.5 * x[:,1])))\n", | ||
"\n", | ||
"exec(input().strip())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## [10_NumPy_21] 11_NumPy_★★_Slicing and Element-wise Op." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"\n", | ||
"def sum_2_rows(M):\n", | ||
" return M[::2,:]+M[1::2,:]\n", | ||
"\n", | ||
"def sum_left_right(M):\n", | ||
" return M[:,:M.shape[1]//2]+M[:,M.shape[1]//2:]\n", | ||
"\n", | ||
"def sum_upper_lower(M):\n", | ||
" return M[:M.shape[0]//2,:]+M[M.shape[0]//2:,:]\n", | ||
"\n", | ||
"def sum_4_quadrants(M):\n", | ||
" return sum_left_right(sum_upper_lower(M))\n", | ||
"\n", | ||
"def sum_4_cells(M):\n", | ||
" return M[::2,::2]+M[::2,1::2]+M[1::2,::2]+M[1::2,1::2]\n", | ||
"\n", | ||
"def count_leap_years(years):\n", | ||
" return np.sum((years%4==0)&((years%100!=0)|(years%400==0)))" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## [10_NumPy_22] 11_NumPy_★★_Outer_Product" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"\n", | ||
"def mult_table(nrows, ncols):\n", | ||
" return np.outer(np.arange(1,nrows+1),np.arange(1,ncols+1))\n", | ||
"\n", | ||
"exec(input().strip())" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## [10_NumPy_23] 11_NumPy_★★_Lower_than_Mean" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 48, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"wtf\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"import numpy as np\n", | ||
"\n", | ||
"read_data=lambda:(np.array([float(x)for x in input().split()]),np.array([[int(r)for r in input().split()]for i in'0'*int(input())]))\n", | ||
"\n", | ||
"def report_lower_than_mean(weight, data):\n", | ||
" mean = np.mean(data[:,1:] * weight)\n", | ||
" result = data[np.mean(weight * data[:,1:], axis=1) < mean][:,0]\n", | ||
" print(\", \".join([str(id) for id in result]) if result.shape[0] > 0 else \"None\")\n", | ||
"\n", | ||
"exec(input().strip())\n" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## [10_NumPy_24] 11_NumPy_★★_Peak_Indexes" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import numpy as np\n", | ||
"def peak_indexes(x):\n", | ||
" # x is an array containing values\n", | ||
" # return an array listing indexes of “peaks”\n", | ||
" pass\n", | ||
"\n", | ||
"def main():\n", | ||
" d = np.array([float(e) for e in input().split()])\n", | ||
" pos = peak_indexes(np.array(d))\n", | ||
" if len(pos) > 0:\n", | ||
" print(\", \".join([str(e) for e in pos]))\n", | ||
" else:\n", | ||
" print(\"No peaks\")\n", | ||
"\n", | ||
"exec(input().strip()) # Don't remove this line\n" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3.9.10 64-bit", | ||
"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.9.10" | ||
}, | ||
"orig_nbformat": 4, | ||
"vscode": { | ||
"interpreter": { | ||
"hash": "b0fa6594d8f4cbf19f97940f81e996739fb7646882a419484c72d19e05852a7e" | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.