{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-10-13T05:08:13.446518Z","iopub.execute_input":"2022-10-13T05:08:13.446970Z","iopub.status.idle":"2022-10-13T05:08:13.453338Z","shell.execute_reply.started":"2022-10-13T05:08:13.446936Z","shell.execute_reply":"2022-10-13T05:08:13.452101Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import math\nimport scipy\nfrom scipy import constants","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:11:09.401837Z","iopub.execute_input":"2022-10-13T04:11:09.402242Z","iopub.status.idle":"2022-10-13T04:11:09.407343Z","shell.execute_reply.started":"2022-10-13T04:11:09.402211Z","shell.execute_reply":"2022-10-13T04:11:09.406244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(scipy.__version__)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T03:58:39.889414Z","iopub.execute_input":"2022-10-13T03:58:39.889892Z","iopub.status.idle":"2022-10-13T03:58:39.895933Z","shell.execute_reply.started":"2022-10-13T03:58:39.889853Z","shell.execute_reply":"2022-10-13T03:58:39.894924Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Constants","metadata":{}},{"cell_type":"code","source":"print(dir(constants))","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:01:27.899971Z","iopub.execute_input":"2022-10-13T04:01:27.900428Z","iopub.status.idle":"2022-10-13T04:01:27.906698Z","shell.execute_reply.started":"2022-10-13T04:01:27.900391Z","shell.execute_reply":"2022-10-13T04:01:27.905447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(constants.mebi)\nprint(constants.electron_volt)\nprint(constants.gallon_US)\nprint(constants.gram)\nprint(constants.lb)\nprint(constants.degree)\nprint(constants.minute)\nprint(constants.mile)\nprint(constants.psi)\nprint(constants.hectare)\nprint(constants.mach)\nprint(constants.horsepower)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:08:37.011590Z","iopub.execute_input":"2022-10-13T04:08:37.012078Z","iopub.status.idle":"2022-10-13T04:08:37.020539Z","shell.execute_reply.started":"2022-10-13T04:08:37.012038Z","shell.execute_reply":"2022-10-13T04:08:37.019065Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Optimizers","metadata":{}},{"cell_type":"code","source":"from scipy import optimize","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:10:17.569071Z","iopub.execute_input":"2022-10-13T04:10:17.570273Z","iopub.status.idle":"2022-10-13T04:10:17.709040Z","shell.execute_reply.started":"2022-10-13T04:10:17.570232Z","shell.execute_reply":"2022-10-13T04:10:17.707715Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(dir(optimize))","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:15:06.501481Z","iopub.execute_input":"2022-10-13T04:15:06.502065Z","iopub.status.idle":"2022-10-13T04:15:06.508793Z","shell.execute_reply.started":"2022-10-13T04:15:06.502019Z","shell.execute_reply":"2022-10-13T04:15:06.507567Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def func(x):\n    return x**3 + x*math.cos(x) +3","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:26:00.712094Z","iopub.execute_input":"2022-10-13T04:26:00.712516Z","iopub.status.idle":"2022-10-13T04:26:00.717950Z","shell.execute_reply.started":"2022-10-13T04:26:00.712480Z","shell.execute_reply":"2022-10-13T04:26:00.716690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"optimize.root(func,1)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:26:02.525307Z","iopub.execute_input":"2022-10-13T04:26:02.525992Z","iopub.status.idle":"2022-10-13T04:26:02.535866Z","shell.execute_reply.started":"2022-10-13T04:26:02.525953Z","shell.execute_reply":"2022-10-13T04:26:02.534609Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"optimize.minimize(func, 0, method='CG')# 'CG','BFGS','Newton-CG','L-BFGS-B','TNC','COBYLA','SLSQP'","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:28:48.352931Z","iopub.execute_input":"2022-10-13T04:28:48.353318Z","iopub.status.idle":"2022-10-13T04:28:48.627910Z","shell.execute_reply.started":"2022-10-13T04:28:48.353288Z","shell.execute_reply":"2022-10-13T04:28:48.626434Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Sparse Data","metadata":{}},{"cell_type":"code","source":"from scipy import sparse","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:35:47.702697Z","iopub.execute_input":"2022-10-13T04:35:47.703113Z","iopub.status.idle":"2022-10-13T04:35:47.708586Z","shell.execute_reply.started":"2022-10-13T04:35:47.703080Z","shell.execute_reply":"2022-10-13T04:35:47.707363Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"arr1 = np.array([3,0,1,0,0,1,0,0,0,0,21,0,0,0,5,0,0,0,0,0])","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:57:12.027151Z","iopub.execute_input":"2022-10-13T04:57:12.027784Z","iopub.status.idle":"2022-10-13T04:57:12.032195Z","shell.execute_reply.started":"2022-10-13T04:57:12.027750Z","shell.execute_reply":"2022-10-13T04:57:12.031233Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(sparse.csr_matrix(arr1))","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:57:12.227536Z","iopub.execute_input":"2022-10-13T04:57:12.227965Z","iopub.status.idle":"2022-10-13T04:57:12.234299Z","shell.execute_reply.started":"2022-10-13T04:57:12.227927Z","shell.execute_reply":"2022-10-13T04:57:12.233102Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sparse.csr_matrix(arr1).data","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:57:12.526977Z","iopub.execute_input":"2022-10-13T04:57:12.529801Z","iopub.status.idle":"2022-10-13T04:57:12.536925Z","shell.execute_reply.started":"2022-10-13T04:57:12.529744Z","shell.execute_reply":"2022-10-13T04:57:12.535758Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(sparse.csr_matrix(arr1).count_nonzero())","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:57:12.774922Z","iopub.execute_input":"2022-10-13T04:57:12.775341Z","iopub.status.idle":"2022-10-13T04:57:12.782390Z","shell.execute_reply.started":"2022-10-13T04:57:12.775306Z","shell.execute_reply":"2022-10-13T04:57:12.781106Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"arr2 = np.array([[0, 1,0], [1,0, 0], [2, 0, 0]])","metadata":{"execution":{"iopub.status.busy":"2022-10-13T04:58:59.428419Z","iopub.execute_input":"2022-10-13T04:58:59.429431Z","iopub.status.idle":"2022-10-13T04:58:59.434989Z","shell.execute_reply.started":"2022-10-13T04:58:59.429387Z","shell.execute_reply":"2022-10-13T04:58:59.433895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(sparse.csr_matrix(arr2).tocsc())","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:00:19.236263Z","iopub.execute_input":"2022-10-13T05:00:19.236640Z","iopub.status.idle":"2022-10-13T05:00:19.242858Z","shell.execute_reply.started":"2022-10-13T05:00:19.236609Z","shell.execute_reply":"2022-10-13T05:00:19.241659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from scipy.sparse.csgraph import connected_components","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:04:41.426968Z","iopub.execute_input":"2022-10-13T05:04:41.427402Z","iopub.status.idle":"2022-10-13T05:04:41.432774Z","shell.execute_reply.started":"2022-10-13T05:04:41.427368Z","shell.execute_reply":"2022-10-13T05:04:41.431898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"arr = np.array([\n  [0, 1, 2],\n  [1, 0, 0],\n  [2, 0, 0]\n])\n\nnewarr = sparse.csr_matrix(arr)\n\nprint(connected_components(newarr))","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:05:01.913627Z","iopub.execute_input":"2022-10-13T05:05:01.914714Z","iopub.status.idle":"2022-10-13T05:05:01.924337Z","shell.execute_reply.started":"2022-10-13T05:05:01.914658Z","shell.execute_reply":"2022-10-13T05:05:01.923238Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Dijkstra","metadata":{}},{"cell_type":"code","source":"from scipy.sparse.csgraph import dijkstra","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:05:16.903851Z","iopub.execute_input":"2022-10-13T05:05:16.904290Z","iopub.status.idle":"2022-10-13T05:05:16.909413Z","shell.execute_reply.started":"2022-10-13T05:05:16.904253Z","shell.execute_reply":"2022-10-13T05:05:16.908283Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(dijkstra(newarr, return_predecessors=True, indices=0))","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:05:28.624007Z","iopub.execute_input":"2022-10-13T05:05:28.624423Z","iopub.status.idle":"2022-10-13T05:05:28.630957Z","shell.execute_reply.started":"2022-10-13T05:05:28.624389Z","shell.execute_reply":"2022-10-13T05:05:28.630085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Floyd Warshall","metadata":{}},{"cell_type":"code","source":"from scipy.sparse.csgraph import floyd_warshall","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:05:44.773851Z","iopub.execute_input":"2022-10-13T05:05:44.774644Z","iopub.status.idle":"2022-10-13T05:05:44.780111Z","shell.execute_reply.started":"2022-10-13T05:05:44.774606Z","shell.execute_reply":"2022-10-13T05:05:44.778988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(floyd_warshall(newarr, return_predecessors=True))","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:05:55.533548Z","iopub.execute_input":"2022-10-13T05:05:55.533969Z","iopub.status.idle":"2022-10-13T05:05:55.540920Z","shell.execute_reply.started":"2022-10-13T05:05:55.533934Z","shell.execute_reply":"2022-10-13T05:05:55.539738Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Bellman Ford","metadata":{}},{"cell_type":"code","source":"from scipy.sparse.csgraph import bellman_ford","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:06:06.354333Z","iopub.execute_input":"2022-10-13T05:06:06.354754Z","iopub.status.idle":"2022-10-13T05:06:06.360907Z","shell.execute_reply.started":"2022-10-13T05:06:06.354706Z","shell.execute_reply":"2022-10-13T05:06:06.359621Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(bellman_ford(newarr, return_predecessors=True, indices=0))","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:06:20.672825Z","iopub.execute_input":"2022-10-13T05:06:20.673219Z","iopub.status.idle":"2022-10-13T05:06:20.679544Z","shell.execute_reply.started":"2022-10-13T05:06:20.673186Z","shell.execute_reply":"2022-10-13T05:06:20.678376Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Depth First Order","metadata":{}},{"cell_type":"code","source":"from scipy.sparse.csgraph import depth_first_order","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:06:33.157966Z","iopub.execute_input":"2022-10-13T05:06:33.158390Z","iopub.status.idle":"2022-10-13T05:06:33.163860Z","shell.execute_reply.started":"2022-10-13T05:06:33.158354Z","shell.execute_reply":"2022-10-13T05:06:33.162368Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(depth_first_order(newarr, 1))","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:06:42.884560Z","iopub.execute_input":"2022-10-13T05:06:42.884994Z","iopub.status.idle":"2022-10-13T05:06:42.891248Z","shell.execute_reply.started":"2022-10-13T05:06:42.884959Z","shell.execute_reply":"2022-10-13T05:06:42.890031Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Breadth First Order","metadata":{}},{"cell_type":"code","source":"from scipy.sparse.csgraph import breadth_first_order","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:06:57.905620Z","iopub.execute_input":"2022-10-13T05:06:57.906070Z","iopub.status.idle":"2022-10-13T05:06:57.911245Z","shell.execute_reply.started":"2022-10-13T05:06:57.906034Z","shell.execute_reply":"2022-10-13T05:06:57.910186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(breadth_first_order(newarr, 1))","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:07:11.015009Z","iopub.execute_input":"2022-10-13T05:07:11.015385Z","iopub.status.idle":"2022-10-13T05:07:11.023289Z","shell.execute_reply.started":"2022-10-13T05:07:11.015354Z","shell.execute_reply":"2022-10-13T05:07:11.022201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Triangulation","metadata":{}},{"cell_type":"code","source":"from scipy.spatial import Delaunay\n\npoints = np.array([\n  [2, 4],\n  [3, 4],\n  [3, 0],\n  [2, 2],\n  [4, 1]\n])\n\nsimplices = Delaunay(points).simplices\n\nplt.triplot(points[:, 0], points[:, 1], simplices)\nplt.scatter(points[:, 0], points[:, 1], color='r')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:08:19.416112Z","iopub.execute_input":"2022-10-13T05:08:19.416944Z","iopub.status.idle":"2022-10-13T05:08:19.668972Z","shell.execute_reply.started":"2022-10-13T05:08:19.416903Z","shell.execute_reply":"2022-10-13T05:08:19.667995Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Convex Hull","metadata":{}},{"cell_type":"code","source":"from scipy.spatial import ConvexHull","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:08:51.525981Z","iopub.execute_input":"2022-10-13T05:08:51.528609Z","iopub.status.idle":"2022-10-13T05:08:51.532626Z","shell.execute_reply.started":"2022-10-13T05:08:51.528565Z","shell.execute_reply":"2022-10-13T05:08:51.531876Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"points = np.array([\n  [2, 4],\n  [3, 4],\n  [3, 0],\n  [2, 2],\n  [4, 1],\n  [1, 2],\n  [5, 0],\n  [3, 1],\n  [1, 2],\n  [0, 2]\n])\n\nhull = ConvexHull(points)\nhull_points = hull.simplices\n\nplt.scatter(points[:,0], points[:,1])\nfor simplex in hull_points:\n  plt.plot(points[simplex,0], points[simplex,1], 'k-')\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:09:04.637600Z","iopub.execute_input":"2022-10-13T05:09:04.638047Z","iopub.status.idle":"2022-10-13T05:09:04.829443Z","shell.execute_reply.started":"2022-10-13T05:09:04.638009Z","shell.execute_reply":"2022-10-13T05:09:04.828352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# KDTrees","metadata":{}},{"cell_type":"code","source":"from scipy.spatial import KDTree\n\npoints = [(1, -1), (2, 3), (-2, 3), (2, -3)]\n\nkdtree = KDTree(points)\n\nres = kdtree.query((1, 1))\n\nprint(res)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:09:30.485429Z","iopub.execute_input":"2022-10-13T05:09:30.486143Z","iopub.status.idle":"2022-10-13T05:09:30.495315Z","shell.execute_reply.started":"2022-10-13T05:09:30.486092Z","shell.execute_reply":"2022-10-13T05:09:30.494218Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Euclidean Distance","metadata":{}},{"cell_type":"code","source":"from scipy.spatial.distance import euclidean\n\np1 = (1, 0)\np2 = (10, 2)\n\nres = euclidean(p1, p2)\n\nprint(res)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:09:46.985575Z","iopub.execute_input":"2022-10-13T05:09:46.987043Z","iopub.status.idle":"2022-10-13T05:09:46.994068Z","shell.execute_reply.started":"2022-10-13T05:09:46.986996Z","shell.execute_reply":"2022-10-13T05:09:46.992791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Manhattan Distance","metadata":{}},{"cell_type":"code","source":"from scipy.spatial.distance import cityblock\n\np1 = (1, 0)\np2 = (10, 2)\n\nres = cityblock(p1, p2)\n\nprint(res)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:10:01.167400Z","iopub.execute_input":"2022-10-13T05:10:01.168495Z","iopub.status.idle":"2022-10-13T05:10:01.176403Z","shell.execute_reply.started":"2022-10-13T05:10:01.168444Z","shell.execute_reply":"2022-10-13T05:10:01.174898Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Cosine Distance","metadata":{}},{"cell_type":"code","source":"from scipy.spatial.distance import cosine\n\np1 = (1, 0)\np2 = (10, 2)\n\nres = cosine(p1, p2)\n\nprint(res)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:10:54.045201Z","iopub.execute_input":"2022-10-13T05:10:54.045657Z","iopub.status.idle":"2022-10-13T05:10:54.051739Z","shell.execute_reply.started":"2022-10-13T05:10:54.045618Z","shell.execute_reply":"2022-10-13T05:10:54.050831Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Hamming Distance","metadata":{}},{"cell_type":"code","source":"from scipy.spatial.distance import hamming\n\np1 = (True, False, True)\np2 = (False, True, True)\n\nres = hamming(p1, p2)\n\nprint(res)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:11:07.487110Z","iopub.execute_input":"2022-10-13T05:11:07.487765Z","iopub.status.idle":"2022-10-13T05:11:07.494106Z","shell.execute_reply.started":"2022-10-13T05:11:07.487705Z","shell.execute_reply":"2022-10-13T05:11:07.492985Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Matlab Arrays","metadata":{}},{"cell_type":"code","source":"from scipy import io\n\narr = np.arange(10)\n\nio.savemat('arr.mat', {\"vec\": arr})","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:11:34.354389Z","iopub.execute_input":"2022-10-13T05:11:34.354806Z","iopub.status.idle":"2022-10-13T05:11:34.387382Z","shell.execute_reply.started":"2022-10-13T05:11:34.354763Z","shell.execute_reply":"2022-10-13T05:11:34.386243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"io.savemat('arr.mat', {\"vec\": arr})\n\n# Import:\nmydata = io.loadmat('arr.mat')\n\nprint(mydata)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:12:05.014991Z","iopub.execute_input":"2022-10-13T05:12:05.015387Z","iopub.status.idle":"2022-10-13T05:12:05.023634Z","shell.execute_reply.started":"2022-10-13T05:12:05.015355Z","shell.execute_reply":"2022-10-13T05:12:05.022423Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(mydata['vec'])","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:12:21.634102Z","iopub.execute_input":"2022-10-13T05:12:21.634534Z","iopub.status.idle":"2022-10-13T05:12:21.641467Z","shell.execute_reply.started":"2022-10-13T05:12:21.634497Z","shell.execute_reply":"2022-10-13T05:12:21.640214Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mydata = io.loadmat('arr.mat', squeeze_me=True)\n\nprint(mydata['vec'])","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:12:36.504596Z","iopub.execute_input":"2022-10-13T05:12:36.504990Z","iopub.status.idle":"2022-10-13T05:12:36.511949Z","shell.execute_reply.started":"2022-10-13T05:12:36.504957Z","shell.execute_reply":"2022-10-13T05:12:36.510778Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# 1D Interpolation","metadata":{}},{"cell_type":"code","source":"from scipy.interpolate import interp1d\n\nxs = np.arange(10)\nys = 2*xs + 1\n\ninterp_func = interp1d(xs, ys)\n\nnewarr = interp_func(np.arange(2.1, 3, 0.1))\n\nprint(newarr)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:13:09.786170Z","iopub.execute_input":"2022-10-13T05:13:09.786557Z","iopub.status.idle":"2022-10-13T05:13:09.805624Z","shell.execute_reply.started":"2022-10-13T05:13:09.786526Z","shell.execute_reply":"2022-10-13T05:13:09.804378Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Spline Interpolation","metadata":{}},{"cell_type":"code","source":"from scipy.interpolate import UnivariateSpline\ninterp_func = UnivariateSpline(xs, ys)\n\nnewarr = interp_func(np.arange(2.1, 3, 0.1))\n\nprint(newarr)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:13:45.733173Z","iopub.execute_input":"2022-10-13T05:13:45.733567Z","iopub.status.idle":"2022-10-13T05:13:45.742655Z","shell.execute_reply.started":"2022-10-13T05:13:45.733534Z","shell.execute_reply":"2022-10-13T05:13:45.741345Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Interpolation with Radial Basis Function","metadata":{}},{"cell_type":"code","source":"from scipy.interpolate import Rbf\ninterp_func = Rbf(xs, ys)\n\nnewarr = interp_func(np.arange(2.1, 3, 0.1))\n\nprint(newarr)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:14:28.194589Z","iopub.execute_input":"2022-10-13T05:14:28.195065Z","iopub.status.idle":"2022-10-13T05:14:28.206762Z","shell.execute_reply.started":"2022-10-13T05:14:28.195026Z","shell.execute_reply":"2022-10-13T05:14:28.205803Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# T-Test","metadata":{}},{"cell_type":"code","source":"from scipy.stats import ttest_ind\n\nv1 = np.random.normal(size=100)\nv2 = np.random.normal(size=100)\n\nres = ttest_ind(v1, v2)\n\nprint(res)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:15:09.795695Z","iopub.execute_input":"2022-10-13T05:15:09.796160Z","iopub.status.idle":"2022-10-13T05:15:09.957854Z","shell.execute_reply.started":"2022-10-13T05:15:09.796123Z","shell.execute_reply":"2022-10-13T05:15:09.957045Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# P value ","metadata":{}},{"cell_type":"code","source":"res = ttest_ind(v1, v2).pvalue\n\nprint(res)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:15:24.614369Z","iopub.execute_input":"2022-10-13T05:15:24.614796Z","iopub.status.idle":"2022-10-13T05:15:24.621057Z","shell.execute_reply.started":"2022-10-13T05:15:24.614754Z","shell.execute_reply":"2022-10-13T05:15:24.619979Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# KS-Test\n","metadata":{}},{"cell_type":"code","source":"from scipy.stats import kstest\n\nv = np.random.normal(size=100)\n\nres = kstest(v, 'norm')\n\nprint(res)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:15:40.684352Z","iopub.execute_input":"2022-10-13T05:15:40.685469Z","iopub.status.idle":"2022-10-13T05:15:40.693918Z","shell.execute_reply.started":"2022-10-13T05:15:40.685425Z","shell.execute_reply":"2022-10-13T05:15:40.692918Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Statistical Description of Data","metadata":{}},{"cell_type":"code","source":"from scipy.stats import describe\n\nv = np.random.normal(size=100)\nres = describe(v)\n\nprint(res)","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:15:58.044798Z","iopub.execute_input":"2022-10-13T05:15:58.045991Z","iopub.status.idle":"2022-10-13T05:15:58.052736Z","shell.execute_reply.started":"2022-10-13T05:15:58.045947Z","shell.execute_reply":"2022-10-13T05:15:58.051542Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Skewness and Kurtosis ","metadata":{}},{"cell_type":"code","source":"from scipy.stats import skew, kurtosis\n\nv = np.random.normal(size=100)\n\nprint(skew(v))\nprint(kurtosis(v))","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:16:17.375769Z","iopub.execute_input":"2022-10-13T05:16:17.376156Z","iopub.status.idle":"2022-10-13T05:16:17.383143Z","shell.execute_reply.started":"2022-10-13T05:16:17.376127Z","shell.execute_reply":"2022-10-13T05:16:17.382010Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Normal test","metadata":{}},{"cell_type":"code","source":"from scipy.stats import normaltest\n\nv = np.random.normal(size=100)\n\nprint(normaltest(v))","metadata":{"execution":{"iopub.status.busy":"2022-10-13T05:16:32.596799Z","iopub.execute_input":"2022-10-13T05:16:32.597237Z","iopub.status.idle":"2022-10-13T05:16:32.604687Z","shell.execute_reply.started":"2022-10-13T05:16:32.597199Z","shell.execute_reply":"2022-10-13T05:16:32.603816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}