Skip to content
This repository was archived by the owner on Sep 22, 2024. It is now read-only.

Commit 9127769

Browse files
Completion of Modules
* Added questions to modules * Revised README * Other minor fixes
2 parents e57a7c8 + 33d38ba commit 9127769

File tree

7 files changed

+1450
-154
lines changed

7 files changed

+1450
-154
lines changed
File renamed without changes.

Lookups/NumPyBasics.ipynb

Lines changed: 318 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,318 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# NumPy Basics"
8+
]
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": null,
13+
"metadata": {
14+
"ExecuteTime": {
15+
"end_time": "2018-05-23T15:35:23.903252Z",
16+
"start_time": "2018-05-23T15:35:23.605538Z"
17+
}
18+
},
19+
"outputs": [],
20+
"source": [
21+
"# Importing\n",
22+
"import numpy as np"
23+
]
24+
},
25+
{
26+
"cell_type": "markdown",
27+
"metadata": {},
28+
"source": [
29+
"## Creation of np.array"
30+
]
31+
},
32+
{
33+
"cell_type": "code",
34+
"execution_count": null,
35+
"metadata": {
36+
"ExecuteTime": {
37+
"end_time": "2018-05-23T15:35:23.917148Z",
38+
"start_time": "2018-05-23T15:35:23.906370Z"
39+
}
40+
},
41+
"outputs": [],
42+
"source": [
43+
"# Creation of np.array from list\n",
44+
"list_a = [1, 2, 3]\n",
45+
"a = np.array(list_a)\n",
46+
"print(a)\n",
47+
"print(type(a))\n",
48+
"print(a.shape)"
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": null,
54+
"metadata": {
55+
"ExecuteTime": {
56+
"end_time": "2018-05-23T15:35:23.935386Z",
57+
"start_time": "2018-05-23T15:35:23.922430Z"
58+
}
59+
},
60+
"outputs": [],
61+
"source": [
62+
"# 2D array\n",
63+
"list_b = [[1, 0, 0],\n",
64+
" [0, 1, 0],\n",
65+
" [0, 0, 1]]\n",
66+
"b = np.array(list_b)\n",
67+
"print(b)\n",
68+
"print(type(b))\n",
69+
"print(b.shape)"
70+
]
71+
},
72+
{
73+
"cell_type": "code",
74+
"execution_count": null,
75+
"metadata": {
76+
"ExecuteTime": {
77+
"end_time": "2018-05-23T15:35:23.954285Z",
78+
"start_time": "2018-05-23T15:35:23.939383Z"
79+
}
80+
},
81+
"outputs": [],
82+
"source": [
83+
"# To create arrays of 0s and 1s\n",
84+
"zero_array = np.zeros((2,3))\n",
85+
"one_array = np.ones((3,4))\n",
86+
"print(zero_array)\n",
87+
"print(one_array)"
88+
]
89+
},
90+
{
91+
"cell_type": "code",
92+
"execution_count": null,
93+
"metadata": {
94+
"ExecuteTime": {
95+
"end_time": "2018-05-23T15:35:23.976733Z",
96+
"start_time": "2018-05-23T15:35:23.958331Z"
97+
}
98+
},
99+
"outputs": [],
100+
"source": [
101+
"# Generating random numbers\n",
102+
"c = np.random.randint(low=1, high=10, size=(3,3))\n",
103+
"d = np.random.rand(8, 3)\n",
104+
"e = np.random.random_sample((3, 4))\n",
105+
"print(c)\n",
106+
"print(d)\n",
107+
"print(e)"
108+
]
109+
},
110+
{
111+
"cell_type": "markdown",
112+
"metadata": {},
113+
"source": [
114+
"## Reshaping arrays"
115+
]
116+
},
117+
{
118+
"cell_type": "code",
119+
"execution_count": null,
120+
"metadata": {
121+
"ExecuteTime": {
122+
"end_time": "2018-05-23T15:35:23.999537Z",
123+
"start_time": "2018-05-23T15:35:23.980468Z"
124+
}
125+
},
126+
"outputs": [],
127+
"source": [
128+
"# Reshaping arrays into required shape\n",
129+
"d_1 = np.reshape(d, newshape=(6, 4))\n",
130+
"# In order to reshape from 8x3 to 6x4, size can also be mentioned as (6, -1)\n",
131+
"# The remaining factor (in place of -1) is automatically computed\n",
132+
"d_2 = d.reshape((6, -1))\n",
133+
"print(d_1)\n",
134+
"print(d_2)\n",
135+
"print(d_1 == d_2)"
136+
]
137+
},
138+
{
139+
"cell_type": "code",
140+
"execution_count": null,
141+
"metadata": {
142+
"ExecuteTime": {
143+
"end_time": "2018-05-23T15:35:24.013137Z",
144+
"start_time": "2018-05-23T15:35:24.005781Z"
145+
}
146+
},
147+
"outputs": [],
148+
"source": [
149+
"# Task: Try to reshape the array into a 3D array of shape 2x3x4"
150+
]
151+
},
152+
{
153+
"cell_type": "markdown",
154+
"metadata": {},
155+
"source": [
156+
"## Deletion of elements"
157+
]
158+
},
159+
{
160+
"cell_type": "code",
161+
"execution_count": null,
162+
"metadata": {
163+
"ExecuteTime": {
164+
"end_time": "2018-05-23T15:35:24.030355Z",
165+
"start_time": "2018-05-23T15:35:24.020446Z"
166+
}
167+
},
168+
"outputs": [],
169+
"source": [
170+
"# Deletion of rows/columns\n",
171+
"d_col_delete = np.delete(d, 1, axis=1)\n",
172+
"d_row_delete = np.delete(d, 2, axis=0)\n",
173+
"print(d_col_delete.shape)\n",
174+
"print(d_row_delete.shape)"
175+
]
176+
},
177+
{
178+
"cell_type": "code",
179+
"execution_count": null,
180+
"metadata": {
181+
"ExecuteTime": {
182+
"end_time": "2018-05-23T15:35:24.043052Z",
183+
"start_time": "2018-05-23T15:35:24.036309Z"
184+
}
185+
},
186+
"outputs": [],
187+
"source": [
188+
"# Learn the concepts of axis properly\n",
189+
"# Check StackOverflow or NumPy documentation for more details"
190+
]
191+
},
192+
{
193+
"cell_type": "code",
194+
"execution_count": null,
195+
"metadata": {
196+
"ExecuteTime": {
197+
"end_time": "2018-05-23T15:35:24.054460Z",
198+
"start_time": "2018-05-23T15:35:24.048648Z"
199+
}
200+
},
201+
"outputs": [],
202+
"source": [
203+
"# Task: Delete a particular element of array `c`"
204+
]
205+
},
206+
{
207+
"cell_type": "markdown",
208+
"metadata": {},
209+
"source": [
210+
"## Merging Rows or Columns"
211+
]
212+
},
213+
{
214+
"cell_type": "code",
215+
"execution_count": null,
216+
"metadata": {
217+
"ExecuteTime": {
218+
"end_time": "2018-05-23T15:35:24.065854Z",
219+
"start_time": "2018-05-23T15:35:24.059225Z"
220+
}
221+
},
222+
"outputs": [],
223+
"source": [
224+
"# Merging Rows/Columns\n",
225+
"merge_rows = np.vstack((c, d))\n",
226+
"merge_cols = np.hstack((c, e))"
227+
]
228+
},
229+
{
230+
"cell_type": "code",
231+
"execution_count": null,
232+
"metadata": {
233+
"ExecuteTime": {
234+
"end_time": "2018-05-23T15:35:24.081593Z",
235+
"start_time": "2018-05-23T15:35:24.071818Z"
236+
}
237+
},
238+
"outputs": [],
239+
"source": [
240+
"print(mergeRows)"
241+
]
242+
},
243+
{
244+
"cell_type": "code",
245+
"execution_count": null,
246+
"metadata": {
247+
"ExecuteTime": {
248+
"end_time": "2018-05-23T15:35:24.095793Z",
249+
"start_time": "2018-05-23T15:35:24.087851Z"
250+
}
251+
},
252+
"outputs": [],
253+
"source": [
254+
"print(mergeCols)"
255+
]
256+
},
257+
{
258+
"cell_type": "code",
259+
"execution_count": null,
260+
"metadata": {
261+
"ExecuteTime": {
262+
"end_time": "2018-05-23T15:35:24.106243Z",
263+
"start_time": "2018-05-23T15:35:24.100140Z"
264+
}
265+
},
266+
"outputs": [],
267+
"source": [
268+
"# Task: Try using np.concatenate to perform the above operations"
269+
]
270+
},
271+
{
272+
"cell_type": "markdown",
273+
"metadata": {},
274+
"source": [
275+
"# Aggregate Functions"
276+
]
277+
},
278+
{
279+
"cell_type": "code",
280+
"execution_count": null,
281+
"metadata": {
282+
"ExecuteTime": {
283+
"end_time": "2018-05-23T15:35:24.115888Z",
284+
"start_time": "2018-05-23T15:35:24.110775Z"
285+
}
286+
},
287+
"outputs": [],
288+
"source": [
289+
"# Task: Find the row-wise minimum of the array `c`\n",
290+
"# Task: find the column-wise mean of array `d`\n",
291+
"# Task: Find the row-wise mean of array `e`\n",
292+
"# Task: Find the maximum of all values in the array `c`"
293+
]
294+
}
295+
],
296+
"metadata": {
297+
"anaconda-cloud": {},
298+
"kernelspec": {
299+
"display_name": "Python 3",
300+
"language": "python",
301+
"name": "python3"
302+
},
303+
"language_info": {
304+
"codemirror_mode": {
305+
"name": "ipython",
306+
"version": 3
307+
},
308+
"file_extension": ".py",
309+
"mimetype": "text/x-python",
310+
"name": "python",
311+
"nbconvert_exporter": "python",
312+
"pygments_lexer": "ipython3",
313+
"version": "3.7.3"
314+
}
315+
},
316+
"nbformat": 4,
317+
"nbformat_minor": 2
318+
}

0 commit comments

Comments
 (0)