myawesomepkg 0.1.5__py3-none-any.whl → 0.1.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- myawesomepkg/TSAPY1/1 (A) Working with Numpy Arrays.py +1146 -0
- myawesomepkg/TSAPY1/1(B)Aggregation (1).py +319 -0
- myawesomepkg/TSAPY1/1(C) Broadcasting .py +328 -0
- myawesomepkg/TSAPY1/2(a) Comparison, Masking And Boolean Logic (1).py +497 -0
- myawesomepkg/TSAPY1/2(b)Fancy Indexing.py +594 -0
- myawesomepkg/TSAPY1/2(c) Sorting Arrays.py +528 -0
- myawesomepkg/TSAPY1/2(d) Structured Array.py +350 -0
- myawesomepkg/TSAPY1/3 (A) Handling Missing Data.py +1013 -0
- myawesomepkg/TSAPY1/4A_Merge_Joins.py +1209 -0
- myawesomepkg/TSAPY1/Aggregation_Groupin_Pivot_Filter_Vectorice_Time_Series.py +1999 -0
- myawesomepkg/TSAPY1/Combining_Joins.py +1209 -0
- myawesomepkg/TSAPY1/Pract3_C.py +482 -0
- myawesomepkg/TSAPY1/Pract5_Data_Visualization.py +481 -0
- myawesomepkg/TSAPY1/Practical 6.py +860 -0
- myawesomepkg/TSAPY1/pract3A-B.py +3212 -0
- {myawesomepkg-0.1.5.dist-info → myawesomepkg-0.1.6.dist-info}/METADATA +1 -1
- {myawesomepkg-0.1.5.dist-info → myawesomepkg-0.1.6.dist-info}/RECORD +19 -4
- {myawesomepkg-0.1.5.dist-info → myawesomepkg-0.1.6.dist-info}/WHEEL +0 -0
- {myawesomepkg-0.1.5.dist-info → myawesomepkg-0.1.6.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,1146 @@
|
|
1
|
+
{
|
2
|
+
"cells": [
|
3
|
+
{
|
4
|
+
"cell_type": "code",
|
5
|
+
"execution_count": 1,
|
6
|
+
"id": "169e80fc",
|
7
|
+
"metadata": {},
|
8
|
+
"outputs": [
|
9
|
+
{
|
10
|
+
"name": "stdout",
|
11
|
+
"output_type": "stream",
|
12
|
+
"text": [
|
13
|
+
"Requirement already satisfied: numpy in c:\\users\\lap-01\\anaconda3\\lib\\site-packages (1.21.5)\n",
|
14
|
+
"Note: you may need to restart the kernel to use updated packages.\n"
|
15
|
+
]
|
16
|
+
}
|
17
|
+
],
|
18
|
+
"source": [
|
19
|
+
"pip install numpy"
|
20
|
+
]
|
21
|
+
},
|
22
|
+
{
|
23
|
+
"cell_type": "code",
|
24
|
+
"execution_count": 3,
|
25
|
+
"id": "94111d0c",
|
26
|
+
"metadata": {},
|
27
|
+
"outputs": [],
|
28
|
+
"source": [
|
29
|
+
"import numpy as np"
|
30
|
+
]
|
31
|
+
},
|
32
|
+
{
|
33
|
+
"cell_type": "code",
|
34
|
+
"execution_count": 5,
|
35
|
+
"id": "10326722",
|
36
|
+
"metadata": {},
|
37
|
+
"outputs": [],
|
38
|
+
"source": [
|
39
|
+
"# NumPy Array A-dimensional arrayttributes\n",
|
40
|
+
"import numpy as np\n",
|
41
|
+
"np.random.seed(0) # seed for reproducibility\n",
|
42
|
+
"x1 = np.random.randint(10, size=6) # One-dimensional array\n",
|
43
|
+
"x2 = np.random.randint(10, size=(3, 4)) # Two-dimensional array\n",
|
44
|
+
"x3 = np.random.randint(10, size=(3, 4, 5)) # Three-dimensional array"
|
45
|
+
]
|
46
|
+
},
|
47
|
+
{
|
48
|
+
"cell_type": "code",
|
49
|
+
"execution_count": 6,
|
50
|
+
"id": "3a4b0eee",
|
51
|
+
"metadata": {},
|
52
|
+
"outputs": [
|
53
|
+
{
|
54
|
+
"name": "stdout",
|
55
|
+
"output_type": "stream",
|
56
|
+
"text": [
|
57
|
+
"x3 ndim: 3\n",
|
58
|
+
"x3 shape: (3, 4, 5)\n",
|
59
|
+
"x3 size: 60\n"
|
60
|
+
]
|
61
|
+
}
|
62
|
+
],
|
63
|
+
"source": [
|
64
|
+
"print(\"x3 ndim: \", x3.ndim)\n",
|
65
|
+
"print(\"x3 shape:\", x3.shape)\n",
|
66
|
+
"print(\"x3 size: \", x3.size)\n"
|
67
|
+
]
|
68
|
+
},
|
69
|
+
{
|
70
|
+
"cell_type": "code",
|
71
|
+
"execution_count": 7,
|
72
|
+
"id": "ed81bf92",
|
73
|
+
"metadata": {},
|
74
|
+
"outputs": [
|
75
|
+
{
|
76
|
+
"name": "stdout",
|
77
|
+
"output_type": "stream",
|
78
|
+
"text": [
|
79
|
+
"dtype: int32\n",
|
80
|
+
"itemsize: 4 bytes\n",
|
81
|
+
"nbytes: 240 bytes\n"
|
82
|
+
]
|
83
|
+
}
|
84
|
+
],
|
85
|
+
"source": [
|
86
|
+
"print(\"dtype:\", x3.dtype)\n",
|
87
|
+
"print(\"itemsize:\", x3.itemsize, \"bytes\")\n",
|
88
|
+
"print(\"nbytes:\", x3.nbytes, \"bytes\")\n"
|
89
|
+
]
|
90
|
+
},
|
91
|
+
{
|
92
|
+
"cell_type": "code",
|
93
|
+
"execution_count": 8,
|
94
|
+
"id": "0c7f7ad8",
|
95
|
+
"metadata": {},
|
96
|
+
"outputs": [
|
97
|
+
{
|
98
|
+
"data": {
|
99
|
+
"text/plain": [
|
100
|
+
"array([5, 0, 3, 3, 7, 9])"
|
101
|
+
]
|
102
|
+
},
|
103
|
+
"execution_count": 8,
|
104
|
+
"metadata": {},
|
105
|
+
"output_type": "execute_result"
|
106
|
+
}
|
107
|
+
],
|
108
|
+
"source": [
|
109
|
+
"#Array Indexing: Accessing Single Elements\n",
|
110
|
+
"x1"
|
111
|
+
]
|
112
|
+
},
|
113
|
+
{
|
114
|
+
"cell_type": "code",
|
115
|
+
"execution_count": 9,
|
116
|
+
"id": "feda5fdb",
|
117
|
+
"metadata": {},
|
118
|
+
"outputs": [
|
119
|
+
{
|
120
|
+
"data": {
|
121
|
+
"text/plain": [
|
122
|
+
"5"
|
123
|
+
]
|
124
|
+
},
|
125
|
+
"execution_count": 9,
|
126
|
+
"metadata": {},
|
127
|
+
"output_type": "execute_result"
|
128
|
+
}
|
129
|
+
],
|
130
|
+
"source": [
|
131
|
+
"x1[0]\n"
|
132
|
+
]
|
133
|
+
},
|
134
|
+
{
|
135
|
+
"cell_type": "code",
|
136
|
+
"execution_count": 10,
|
137
|
+
"id": "b222c117",
|
138
|
+
"metadata": {},
|
139
|
+
"outputs": [
|
140
|
+
{
|
141
|
+
"data": {
|
142
|
+
"text/plain": [
|
143
|
+
"7"
|
144
|
+
]
|
145
|
+
},
|
146
|
+
"execution_count": 10,
|
147
|
+
"metadata": {},
|
148
|
+
"output_type": "execute_result"
|
149
|
+
}
|
150
|
+
],
|
151
|
+
"source": [
|
152
|
+
"x1[4]"
|
153
|
+
]
|
154
|
+
},
|
155
|
+
{
|
156
|
+
"cell_type": "code",
|
157
|
+
"execution_count": 11,
|
158
|
+
"id": "c9828983",
|
159
|
+
"metadata": {},
|
160
|
+
"outputs": [
|
161
|
+
{
|
162
|
+
"data": {
|
163
|
+
"text/plain": [
|
164
|
+
"9"
|
165
|
+
]
|
166
|
+
},
|
167
|
+
"execution_count": 11,
|
168
|
+
"metadata": {},
|
169
|
+
"output_type": "execute_result"
|
170
|
+
}
|
171
|
+
],
|
172
|
+
"source": [
|
173
|
+
"x1[-1]\n"
|
174
|
+
]
|
175
|
+
},
|
176
|
+
{
|
177
|
+
"cell_type": "code",
|
178
|
+
"execution_count": 12,
|
179
|
+
"id": "62a862d4",
|
180
|
+
"metadata": {},
|
181
|
+
"outputs": [
|
182
|
+
{
|
183
|
+
"data": {
|
184
|
+
"text/plain": [
|
185
|
+
"7"
|
186
|
+
]
|
187
|
+
},
|
188
|
+
"execution_count": 12,
|
189
|
+
"metadata": {},
|
190
|
+
"output_type": "execute_result"
|
191
|
+
}
|
192
|
+
],
|
193
|
+
"source": [
|
194
|
+
"x1[-2]"
|
195
|
+
]
|
196
|
+
},
|
197
|
+
{
|
198
|
+
"cell_type": "code",
|
199
|
+
"execution_count": 13,
|
200
|
+
"id": "a038d188",
|
201
|
+
"metadata": {},
|
202
|
+
"outputs": [
|
203
|
+
{
|
204
|
+
"data": {
|
205
|
+
"text/plain": [
|
206
|
+
"array([[3, 5, 2, 4],\n",
|
207
|
+
" [7, 6, 8, 8],\n",
|
208
|
+
" [1, 6, 7, 7]])"
|
209
|
+
]
|
210
|
+
},
|
211
|
+
"execution_count": 13,
|
212
|
+
"metadata": {},
|
213
|
+
"output_type": "execute_result"
|
214
|
+
}
|
215
|
+
],
|
216
|
+
"source": [
|
217
|
+
"x2"
|
218
|
+
]
|
219
|
+
},
|
220
|
+
{
|
221
|
+
"cell_type": "code",
|
222
|
+
"execution_count": 14,
|
223
|
+
"id": "cca28148",
|
224
|
+
"metadata": {},
|
225
|
+
"outputs": [
|
226
|
+
{
|
227
|
+
"data": {
|
228
|
+
"text/plain": [
|
229
|
+
"3"
|
230
|
+
]
|
231
|
+
},
|
232
|
+
"execution_count": 14,
|
233
|
+
"metadata": {},
|
234
|
+
"output_type": "execute_result"
|
235
|
+
}
|
236
|
+
],
|
237
|
+
"source": [
|
238
|
+
"x2[0, 0]\n"
|
239
|
+
]
|
240
|
+
},
|
241
|
+
{
|
242
|
+
"cell_type": "code",
|
243
|
+
"execution_count": 15,
|
244
|
+
"id": "26e981f4",
|
245
|
+
"metadata": {},
|
246
|
+
"outputs": [
|
247
|
+
{
|
248
|
+
"data": {
|
249
|
+
"text/plain": [
|
250
|
+
"1"
|
251
|
+
]
|
252
|
+
},
|
253
|
+
"execution_count": 15,
|
254
|
+
"metadata": {},
|
255
|
+
"output_type": "execute_result"
|
256
|
+
}
|
257
|
+
],
|
258
|
+
"source": [
|
259
|
+
"x2[2, 0]"
|
260
|
+
]
|
261
|
+
},
|
262
|
+
{
|
263
|
+
"cell_type": "code",
|
264
|
+
"execution_count": 16,
|
265
|
+
"id": "f37337e2",
|
266
|
+
"metadata": {},
|
267
|
+
"outputs": [
|
268
|
+
{
|
269
|
+
"data": {
|
270
|
+
"text/plain": [
|
271
|
+
"7"
|
272
|
+
]
|
273
|
+
},
|
274
|
+
"execution_count": 16,
|
275
|
+
"metadata": {},
|
276
|
+
"output_type": "execute_result"
|
277
|
+
}
|
278
|
+
],
|
279
|
+
"source": [
|
280
|
+
"x2[2, -1]\n"
|
281
|
+
]
|
282
|
+
},
|
283
|
+
{
|
284
|
+
"cell_type": "code",
|
285
|
+
"execution_count": 17,
|
286
|
+
"id": "1f4168ce",
|
287
|
+
"metadata": {},
|
288
|
+
"outputs": [
|
289
|
+
{
|
290
|
+
"data": {
|
291
|
+
"text/plain": [
|
292
|
+
"array([[12, 5, 2, 4],\n",
|
293
|
+
" [ 7, 6, 8, 8],\n",
|
294
|
+
" [ 1, 6, 7, 7]])"
|
295
|
+
]
|
296
|
+
},
|
297
|
+
"execution_count": 17,
|
298
|
+
"metadata": {},
|
299
|
+
"output_type": "execute_result"
|
300
|
+
}
|
301
|
+
],
|
302
|
+
"source": [
|
303
|
+
"x2[0, 0] = 12\n",
|
304
|
+
"x2"
|
305
|
+
]
|
306
|
+
},
|
307
|
+
{
|
308
|
+
"cell_type": "code",
|
309
|
+
"execution_count": 18,
|
310
|
+
"id": "9ae4e924",
|
311
|
+
"metadata": {},
|
312
|
+
"outputs": [
|
313
|
+
{
|
314
|
+
"data": {
|
315
|
+
"text/plain": [
|
316
|
+
"array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])"
|
317
|
+
]
|
318
|
+
},
|
319
|
+
"execution_count": 18,
|
320
|
+
"metadata": {},
|
321
|
+
"output_type": "execute_result"
|
322
|
+
}
|
323
|
+
],
|
324
|
+
"source": [
|
325
|
+
"#Array Slicing: Accessing Subarrays\n",
|
326
|
+
"x = np.arange(10)\n",
|
327
|
+
"x"
|
328
|
+
]
|
329
|
+
},
|
330
|
+
{
|
331
|
+
"cell_type": "code",
|
332
|
+
"execution_count": 19,
|
333
|
+
"id": "ab2d6c83",
|
334
|
+
"metadata": {},
|
335
|
+
"outputs": [
|
336
|
+
{
|
337
|
+
"data": {
|
338
|
+
"text/plain": [
|
339
|
+
"array([0, 1, 2, 3, 4])"
|
340
|
+
]
|
341
|
+
},
|
342
|
+
"execution_count": 19,
|
343
|
+
"metadata": {},
|
344
|
+
"output_type": "execute_result"
|
345
|
+
}
|
346
|
+
],
|
347
|
+
"source": [
|
348
|
+
" # first five elements\n",
|
349
|
+
"x[:5]"
|
350
|
+
]
|
351
|
+
},
|
352
|
+
{
|
353
|
+
"cell_type": "code",
|
354
|
+
"execution_count": 20,
|
355
|
+
"id": "c5e4b212",
|
356
|
+
"metadata": {},
|
357
|
+
"outputs": [
|
358
|
+
{
|
359
|
+
"data": {
|
360
|
+
"text/plain": [
|
361
|
+
"array([5, 6, 7, 8, 9])"
|
362
|
+
]
|
363
|
+
},
|
364
|
+
"execution_count": 20,
|
365
|
+
"metadata": {},
|
366
|
+
"output_type": "execute_result"
|
367
|
+
}
|
368
|
+
],
|
369
|
+
"source": [
|
370
|
+
"# elements after index 5\n",
|
371
|
+
"x[5:] "
|
372
|
+
]
|
373
|
+
},
|
374
|
+
{
|
375
|
+
"cell_type": "code",
|
376
|
+
"execution_count": 21,
|
377
|
+
"id": "e5be7ef1",
|
378
|
+
"metadata": {},
|
379
|
+
"outputs": [
|
380
|
+
{
|
381
|
+
"data": {
|
382
|
+
"text/plain": [
|
383
|
+
"array([4, 5, 6])"
|
384
|
+
]
|
385
|
+
},
|
386
|
+
"execution_count": 21,
|
387
|
+
"metadata": {},
|
388
|
+
"output_type": "execute_result"
|
389
|
+
}
|
390
|
+
],
|
391
|
+
"source": [
|
392
|
+
"# middle subarray\n",
|
393
|
+
"x[4:7] "
|
394
|
+
]
|
395
|
+
},
|
396
|
+
{
|
397
|
+
"cell_type": "code",
|
398
|
+
"execution_count": 22,
|
399
|
+
"id": "93edeaf1",
|
400
|
+
"metadata": {},
|
401
|
+
"outputs": [
|
402
|
+
{
|
403
|
+
"data": {
|
404
|
+
"text/plain": [
|
405
|
+
"array([0, 2, 4, 6, 8])"
|
406
|
+
]
|
407
|
+
},
|
408
|
+
"execution_count": 22,
|
409
|
+
"metadata": {},
|
410
|
+
"output_type": "execute_result"
|
411
|
+
}
|
412
|
+
],
|
413
|
+
"source": [
|
414
|
+
"# every other element\n",
|
415
|
+
"x[::2] "
|
416
|
+
]
|
417
|
+
},
|
418
|
+
{
|
419
|
+
"cell_type": "code",
|
420
|
+
"execution_count": 24,
|
421
|
+
"id": "58d6d02a",
|
422
|
+
"metadata": {},
|
423
|
+
"outputs": [
|
424
|
+
{
|
425
|
+
"data": {
|
426
|
+
"text/plain": [
|
427
|
+
"array([1, 3, 5, 7, 9])"
|
428
|
+
]
|
429
|
+
},
|
430
|
+
"execution_count": 24,
|
431
|
+
"metadata": {},
|
432
|
+
"output_type": "execute_result"
|
433
|
+
}
|
434
|
+
],
|
435
|
+
"source": [
|
436
|
+
"# every other element, starting at index 1\n",
|
437
|
+
"x[1::2]"
|
438
|
+
]
|
439
|
+
},
|
440
|
+
{
|
441
|
+
"cell_type": "code",
|
442
|
+
"execution_count": 25,
|
443
|
+
"id": "cd7cec10",
|
444
|
+
"metadata": {},
|
445
|
+
"outputs": [
|
446
|
+
{
|
447
|
+
"data": {
|
448
|
+
"text/plain": [
|
449
|
+
"array([9, 8, 7, 6, 5, 4, 3, 2, 1, 0])"
|
450
|
+
]
|
451
|
+
},
|
452
|
+
"execution_count": 25,
|
453
|
+
"metadata": {},
|
454
|
+
"output_type": "execute_result"
|
455
|
+
}
|
456
|
+
],
|
457
|
+
"source": [
|
458
|
+
"x[::-1] # all elements, reversed"
|
459
|
+
]
|
460
|
+
},
|
461
|
+
{
|
462
|
+
"cell_type": "code",
|
463
|
+
"execution_count": 26,
|
464
|
+
"id": "53a4bd27",
|
465
|
+
"metadata": {},
|
466
|
+
"outputs": [
|
467
|
+
{
|
468
|
+
"data": {
|
469
|
+
"text/plain": [
|
470
|
+
"array([[12, 5, 2, 4],\n",
|
471
|
+
" [ 7, 6, 8, 8],\n",
|
472
|
+
" [ 1, 6, 7, 7]])"
|
473
|
+
]
|
474
|
+
},
|
475
|
+
"execution_count": 26,
|
476
|
+
"metadata": {},
|
477
|
+
"output_type": "execute_result"
|
478
|
+
}
|
479
|
+
],
|
480
|
+
"source": [
|
481
|
+
"#Multidimensional Arrays\n",
|
482
|
+
"x2"
|
483
|
+
]
|
484
|
+
},
|
485
|
+
{
|
486
|
+
"cell_type": "code",
|
487
|
+
"execution_count": 27,
|
488
|
+
"id": "7eb3736f",
|
489
|
+
"metadata": {},
|
490
|
+
"outputs": [
|
491
|
+
{
|
492
|
+
"data": {
|
493
|
+
"text/plain": [
|
494
|
+
"array([[12, 5, 2],\n",
|
495
|
+
" [ 7, 6, 8]])"
|
496
|
+
]
|
497
|
+
},
|
498
|
+
"execution_count": 27,
|
499
|
+
"metadata": {},
|
500
|
+
"output_type": "execute_result"
|
501
|
+
}
|
502
|
+
],
|
503
|
+
"source": [
|
504
|
+
"x2[:2, :3] # two rows, three columns"
|
505
|
+
]
|
506
|
+
},
|
507
|
+
{
|
508
|
+
"cell_type": "code",
|
509
|
+
"execution_count": 28,
|
510
|
+
"id": "adb40ab1",
|
511
|
+
"metadata": {},
|
512
|
+
"outputs": [
|
513
|
+
{
|
514
|
+
"data": {
|
515
|
+
"text/plain": [
|
516
|
+
"array([[12, 2],\n",
|
517
|
+
" [ 7, 8],\n",
|
518
|
+
" [ 1, 7]])"
|
519
|
+
]
|
520
|
+
},
|
521
|
+
"execution_count": 28,
|
522
|
+
"metadata": {},
|
523
|
+
"output_type": "execute_result"
|
524
|
+
}
|
525
|
+
],
|
526
|
+
"source": [
|
527
|
+
"x2[:3, ::2] # all rows, every other column"
|
528
|
+
]
|
529
|
+
},
|
530
|
+
{
|
531
|
+
"cell_type": "code",
|
532
|
+
"execution_count": 29,
|
533
|
+
"id": "d4facc1d",
|
534
|
+
"metadata": {},
|
535
|
+
"outputs": [
|
536
|
+
{
|
537
|
+
"data": {
|
538
|
+
"text/plain": [
|
539
|
+
"array([[ 7, 7, 6, 1],\n",
|
540
|
+
" [ 8, 8, 6, 7],\n",
|
541
|
+
" [ 4, 2, 5, 12]])"
|
542
|
+
]
|
543
|
+
},
|
544
|
+
"execution_count": 29,
|
545
|
+
"metadata": {},
|
546
|
+
"output_type": "execute_result"
|
547
|
+
}
|
548
|
+
],
|
549
|
+
"source": [
|
550
|
+
"x2[::-1, ::-1]"
|
551
|
+
]
|
552
|
+
},
|
553
|
+
{
|
554
|
+
"cell_type": "code",
|
555
|
+
"execution_count": 30,
|
556
|
+
"id": "fa0f7197",
|
557
|
+
"metadata": {},
|
558
|
+
"outputs": [
|
559
|
+
{
|
560
|
+
"name": "stdout",
|
561
|
+
"output_type": "stream",
|
562
|
+
"text": [
|
563
|
+
"[12 7 1]\n"
|
564
|
+
]
|
565
|
+
}
|
566
|
+
],
|
567
|
+
"source": [
|
568
|
+
"#Accessing array rows and columns\n",
|
569
|
+
"print(x2[:, 0]) # first column of x2\n"
|
570
|
+
]
|
571
|
+
},
|
572
|
+
{
|
573
|
+
"cell_type": "code",
|
574
|
+
"execution_count": 31,
|
575
|
+
"id": "70f1b70c",
|
576
|
+
"metadata": {},
|
577
|
+
"outputs": [
|
578
|
+
{
|
579
|
+
"name": "stdout",
|
580
|
+
"output_type": "stream",
|
581
|
+
"text": [
|
582
|
+
"[12 5 2 4]\n"
|
583
|
+
]
|
584
|
+
}
|
585
|
+
],
|
586
|
+
"source": [
|
587
|
+
"print(x2[0, :]) # first row of x2"
|
588
|
+
]
|
589
|
+
},
|
590
|
+
{
|
591
|
+
"cell_type": "code",
|
592
|
+
"execution_count": 32,
|
593
|
+
"id": "a21c6589",
|
594
|
+
"metadata": {},
|
595
|
+
"outputs": [
|
596
|
+
{
|
597
|
+
"name": "stdout",
|
598
|
+
"output_type": "stream",
|
599
|
+
"text": [
|
600
|
+
"[12 5 2 4]\n"
|
601
|
+
]
|
602
|
+
}
|
603
|
+
],
|
604
|
+
"source": [
|
605
|
+
" print(x2[0]) # equivalent to x2[0, :]"
|
606
|
+
]
|
607
|
+
},
|
608
|
+
{
|
609
|
+
"cell_type": "code",
|
610
|
+
"execution_count": 33,
|
611
|
+
"id": "17385960",
|
612
|
+
"metadata": {},
|
613
|
+
"outputs": [
|
614
|
+
{
|
615
|
+
"name": "stdout",
|
616
|
+
"output_type": "stream",
|
617
|
+
"text": [
|
618
|
+
"[[12 5 2 4]\n",
|
619
|
+
" [ 7 6 8 8]\n",
|
620
|
+
" [ 1 6 7 7]]\n"
|
621
|
+
]
|
622
|
+
}
|
623
|
+
],
|
624
|
+
"source": [
|
625
|
+
"#Subarrays as no-copy views\n",
|
626
|
+
"print(x2)\n"
|
627
|
+
]
|
628
|
+
},
|
629
|
+
{
|
630
|
+
"cell_type": "code",
|
631
|
+
"execution_count": 34,
|
632
|
+
"id": "6c0e4f3e",
|
633
|
+
"metadata": {},
|
634
|
+
"outputs": [
|
635
|
+
{
|
636
|
+
"name": "stdout",
|
637
|
+
"output_type": "stream",
|
638
|
+
"text": [
|
639
|
+
"[[12 5]\n",
|
640
|
+
" [ 7 6]]\n"
|
641
|
+
]
|
642
|
+
}
|
643
|
+
],
|
644
|
+
"source": [
|
645
|
+
"x2_sub = x2[:2, :2]\n",
|
646
|
+
"print(x2_sub)"
|
647
|
+
]
|
648
|
+
},
|
649
|
+
{
|
650
|
+
"cell_type": "code",
|
651
|
+
"execution_count": 35,
|
652
|
+
"id": "7e38fa6f",
|
653
|
+
"metadata": {},
|
654
|
+
"outputs": [
|
655
|
+
{
|
656
|
+
"name": "stdout",
|
657
|
+
"output_type": "stream",
|
658
|
+
"text": [
|
659
|
+
"[[99 5]\n",
|
660
|
+
" [ 7 6]]\n"
|
661
|
+
]
|
662
|
+
}
|
663
|
+
],
|
664
|
+
"source": [
|
665
|
+
"x2_sub[0, 0] = 99\n",
|
666
|
+
"print(x2_sub)"
|
667
|
+
]
|
668
|
+
},
|
669
|
+
{
|
670
|
+
"cell_type": "code",
|
671
|
+
"execution_count": 36,
|
672
|
+
"id": "3e7b4b73",
|
673
|
+
"metadata": {},
|
674
|
+
"outputs": [
|
675
|
+
{
|
676
|
+
"name": "stdout",
|
677
|
+
"output_type": "stream",
|
678
|
+
"text": [
|
679
|
+
"[[99 5 2 4]\n",
|
680
|
+
" [ 7 6 8 8]\n",
|
681
|
+
" [ 1 6 7 7]]\n"
|
682
|
+
]
|
683
|
+
}
|
684
|
+
],
|
685
|
+
"source": [
|
686
|
+
"print(x2)"
|
687
|
+
]
|
688
|
+
},
|
689
|
+
{
|
690
|
+
"cell_type": "code",
|
691
|
+
"execution_count": 37,
|
692
|
+
"id": "1521ac1f",
|
693
|
+
"metadata": {},
|
694
|
+
"outputs": [
|
695
|
+
{
|
696
|
+
"name": "stdout",
|
697
|
+
"output_type": "stream",
|
698
|
+
"text": [
|
699
|
+
"[[99 5]\n",
|
700
|
+
" [ 7 6]]\n"
|
701
|
+
]
|
702
|
+
}
|
703
|
+
],
|
704
|
+
"source": [
|
705
|
+
"#Creating copies of arrays\n",
|
706
|
+
"x2_sub_copy = x2[:2, :2].copy()\n",
|
707
|
+
"print(x2_sub_copy)"
|
708
|
+
]
|
709
|
+
},
|
710
|
+
{
|
711
|
+
"cell_type": "code",
|
712
|
+
"execution_count": 38,
|
713
|
+
"id": "3bfc6db8",
|
714
|
+
"metadata": {},
|
715
|
+
"outputs": [
|
716
|
+
{
|
717
|
+
"name": "stdout",
|
718
|
+
"output_type": "stream",
|
719
|
+
"text": [
|
720
|
+
"[[42 5]\n",
|
721
|
+
" [ 7 6]]\n"
|
722
|
+
]
|
723
|
+
}
|
724
|
+
],
|
725
|
+
"source": [
|
726
|
+
"x2_sub_copy[0, 0] = 42\n",
|
727
|
+
"print(x2_sub_copy)\n"
|
728
|
+
]
|
729
|
+
},
|
730
|
+
{
|
731
|
+
"cell_type": "code",
|
732
|
+
"execution_count": 39,
|
733
|
+
"id": "80e6304d",
|
734
|
+
"metadata": {},
|
735
|
+
"outputs": [
|
736
|
+
{
|
737
|
+
"name": "stdout",
|
738
|
+
"output_type": "stream",
|
739
|
+
"text": [
|
740
|
+
"[[99 5 2 4]\n",
|
741
|
+
" [ 7 6 8 8]\n",
|
742
|
+
" [ 1 6 7 7]]\n"
|
743
|
+
]
|
744
|
+
}
|
745
|
+
],
|
746
|
+
"source": [
|
747
|
+
"print(x2)\n"
|
748
|
+
]
|
749
|
+
},
|
750
|
+
{
|
751
|
+
"cell_type": "code",
|
752
|
+
"execution_count": 40,
|
753
|
+
"id": "a02b6581",
|
754
|
+
"metadata": {},
|
755
|
+
"outputs": [
|
756
|
+
{
|
757
|
+
"name": "stdout",
|
758
|
+
"output_type": "stream",
|
759
|
+
"text": [
|
760
|
+
"[[1 2 3]\n",
|
761
|
+
" [4 5 6]\n",
|
762
|
+
" [7 8 9]]\n"
|
763
|
+
]
|
764
|
+
}
|
765
|
+
],
|
766
|
+
"source": [
|
767
|
+
"#Reshaping of Arrays\n",
|
768
|
+
"grid = np.arange(1, 10).reshape((3, 3))\n",
|
769
|
+
"print(grid)"
|
770
|
+
]
|
771
|
+
},
|
772
|
+
{
|
773
|
+
"cell_type": "code",
|
774
|
+
"execution_count": 41,
|
775
|
+
"id": "b6d34dc4",
|
776
|
+
"metadata": {},
|
777
|
+
"outputs": [
|
778
|
+
{
|
779
|
+
"data": {
|
780
|
+
"text/plain": [
|
781
|
+
"array([[1, 2, 3]])"
|
782
|
+
]
|
783
|
+
},
|
784
|
+
"execution_count": 41,
|
785
|
+
"metadata": {},
|
786
|
+
"output_type": "execute_result"
|
787
|
+
}
|
788
|
+
],
|
789
|
+
"source": [
|
790
|
+
"x = np.array([1, 2, 3])\n",
|
791
|
+
"# row vector via reshape\n",
|
792
|
+
"x.reshape((1, 3))"
|
793
|
+
]
|
794
|
+
},
|
795
|
+
{
|
796
|
+
"cell_type": "code",
|
797
|
+
"execution_count": 43,
|
798
|
+
"id": "45f902e0",
|
799
|
+
"metadata": {},
|
800
|
+
"outputs": [
|
801
|
+
{
|
802
|
+
"data": {
|
803
|
+
"text/plain": [
|
804
|
+
"array([[1, 2, 3]])"
|
805
|
+
]
|
806
|
+
},
|
807
|
+
"execution_count": 43,
|
808
|
+
"metadata": {},
|
809
|
+
"output_type": "execute_result"
|
810
|
+
}
|
811
|
+
],
|
812
|
+
"source": [
|
813
|
+
"# row vector via newaxis\n",
|
814
|
+
"x[np.newaxis, :]"
|
815
|
+
]
|
816
|
+
},
|
817
|
+
{
|
818
|
+
"cell_type": "code",
|
819
|
+
"execution_count": 44,
|
820
|
+
"id": "7d3e80a5",
|
821
|
+
"metadata": {},
|
822
|
+
"outputs": [
|
823
|
+
{
|
824
|
+
"data": {
|
825
|
+
"text/plain": [
|
826
|
+
"array([[1],\n",
|
827
|
+
" [2],\n",
|
828
|
+
" [3]])"
|
829
|
+
]
|
830
|
+
},
|
831
|
+
"execution_count": 44,
|
832
|
+
"metadata": {},
|
833
|
+
"output_type": "execute_result"
|
834
|
+
}
|
835
|
+
],
|
836
|
+
"source": [
|
837
|
+
"# column vector via reshape\n",
|
838
|
+
"x.reshape((3, 1))\n"
|
839
|
+
]
|
840
|
+
},
|
841
|
+
{
|
842
|
+
"cell_type": "code",
|
843
|
+
"execution_count": 45,
|
844
|
+
"id": "0a7a6e97",
|
845
|
+
"metadata": {},
|
846
|
+
"outputs": [
|
847
|
+
{
|
848
|
+
"data": {
|
849
|
+
"text/plain": [
|
850
|
+
"array([[1],\n",
|
851
|
+
" [2],\n",
|
852
|
+
" [3]])"
|
853
|
+
]
|
854
|
+
},
|
855
|
+
"execution_count": 45,
|
856
|
+
"metadata": {},
|
857
|
+
"output_type": "execute_result"
|
858
|
+
}
|
859
|
+
],
|
860
|
+
"source": [
|
861
|
+
"# column vector via newaxis\n",
|
862
|
+
"x[:, np.newaxis]\n"
|
863
|
+
]
|
864
|
+
},
|
865
|
+
{
|
866
|
+
"cell_type": "code",
|
867
|
+
"execution_count": 46,
|
868
|
+
"id": "a8931161",
|
869
|
+
"metadata": {},
|
870
|
+
"outputs": [
|
871
|
+
{
|
872
|
+
"data": {
|
873
|
+
"text/plain": [
|
874
|
+
"array([1, 2, 3, 3, 2, 1])"
|
875
|
+
]
|
876
|
+
},
|
877
|
+
"execution_count": 46,
|
878
|
+
"metadata": {},
|
879
|
+
"output_type": "execute_result"
|
880
|
+
}
|
881
|
+
],
|
882
|
+
"source": [
|
883
|
+
"#Array Concatenation and Splitting\n",
|
884
|
+
"#Concatenation of arrays\n",
|
885
|
+
"x = np.array([1, 2, 3])\n",
|
886
|
+
"y = np.array([3, 2, 1])\n",
|
887
|
+
"np.concatenate([x, y])"
|
888
|
+
]
|
889
|
+
},
|
890
|
+
{
|
891
|
+
"cell_type": "code",
|
892
|
+
"execution_count": 47,
|
893
|
+
"id": "a3d639da",
|
894
|
+
"metadata": {},
|
895
|
+
"outputs": [
|
896
|
+
{
|
897
|
+
"name": "stdout",
|
898
|
+
"output_type": "stream",
|
899
|
+
"text": [
|
900
|
+
"[ 1 2 3 3 2 1 99 99 99]\n"
|
901
|
+
]
|
902
|
+
}
|
903
|
+
],
|
904
|
+
"source": [
|
905
|
+
"z = [99, 99, 99]\n",
|
906
|
+
"print(np.concatenate([x, y, z]))\n"
|
907
|
+
]
|
908
|
+
},
|
909
|
+
{
|
910
|
+
"cell_type": "code",
|
911
|
+
"execution_count": 48,
|
912
|
+
"id": "d224be9a",
|
913
|
+
"metadata": {},
|
914
|
+
"outputs": [],
|
915
|
+
"source": [
|
916
|
+
"grid = np.array([[1, 2, 3],\n",
|
917
|
+
"[4, 5, 6]])"
|
918
|
+
]
|
919
|
+
},
|
920
|
+
{
|
921
|
+
"cell_type": "code",
|
922
|
+
"execution_count": 49,
|
923
|
+
"id": "164ae8ea",
|
924
|
+
"metadata": {},
|
925
|
+
"outputs": [
|
926
|
+
{
|
927
|
+
"data": {
|
928
|
+
"text/plain": [
|
929
|
+
"array([[1, 2, 3],\n",
|
930
|
+
" [4, 5, 6],\n",
|
931
|
+
" [1, 2, 3],\n",
|
932
|
+
" [4, 5, 6]])"
|
933
|
+
]
|
934
|
+
},
|
935
|
+
"execution_count": 49,
|
936
|
+
"metadata": {},
|
937
|
+
"output_type": "execute_result"
|
938
|
+
}
|
939
|
+
],
|
940
|
+
"source": [
|
941
|
+
"# concatenate along the first axis\n",
|
942
|
+
"np.concatenate([grid, grid])"
|
943
|
+
]
|
944
|
+
},
|
945
|
+
{
|
946
|
+
"cell_type": "code",
|
947
|
+
"execution_count": 50,
|
948
|
+
"id": "8965119f",
|
949
|
+
"metadata": {},
|
950
|
+
"outputs": [
|
951
|
+
{
|
952
|
+
"data": {
|
953
|
+
"text/plain": [
|
954
|
+
"array([[1, 2, 3, 1, 2, 3],\n",
|
955
|
+
" [4, 5, 6, 4, 5, 6]])"
|
956
|
+
]
|
957
|
+
},
|
958
|
+
"execution_count": 50,
|
959
|
+
"metadata": {},
|
960
|
+
"output_type": "execute_result"
|
961
|
+
}
|
962
|
+
],
|
963
|
+
"source": [
|
964
|
+
"# concatenate along the second axis (zero-indexed)\n",
|
965
|
+
"np.concatenate([grid, grid], axis=1)\n"
|
966
|
+
]
|
967
|
+
},
|
968
|
+
{
|
969
|
+
"cell_type": "code",
|
970
|
+
"execution_count": 51,
|
971
|
+
"id": "d79b7ba6",
|
972
|
+
"metadata": {},
|
973
|
+
"outputs": [
|
974
|
+
{
|
975
|
+
"data": {
|
976
|
+
"text/plain": [
|
977
|
+
"array([[1, 2, 3],\n",
|
978
|
+
" [9, 8, 7],\n",
|
979
|
+
" [6, 5, 4]])"
|
980
|
+
]
|
981
|
+
},
|
982
|
+
"execution_count": 51,
|
983
|
+
"metadata": {},
|
984
|
+
"output_type": "execute_result"
|
985
|
+
}
|
986
|
+
],
|
987
|
+
"source": [
|
988
|
+
"x = np.array([1, 2, 3])\n",
|
989
|
+
"grid = np.array([[9, 8, 7],\n",
|
990
|
+
" [6, 5, 4]])\n",
|
991
|
+
"# vertically stack the arrays\n",
|
992
|
+
"np.vstack([x, grid])\n"
|
993
|
+
]
|
994
|
+
},
|
995
|
+
{
|
996
|
+
"cell_type": "code",
|
997
|
+
"execution_count": 52,
|
998
|
+
"id": "f241b0c1",
|
999
|
+
"metadata": {},
|
1000
|
+
"outputs": [
|
1001
|
+
{
|
1002
|
+
"data": {
|
1003
|
+
"text/plain": [
|
1004
|
+
"array([[ 9, 8, 7, 99],\n",
|
1005
|
+
" [ 6, 5, 4, 99]])"
|
1006
|
+
]
|
1007
|
+
},
|
1008
|
+
"execution_count": 52,
|
1009
|
+
"metadata": {},
|
1010
|
+
"output_type": "execute_result"
|
1011
|
+
}
|
1012
|
+
],
|
1013
|
+
"source": [
|
1014
|
+
"# horizontally stack the arrays\n",
|
1015
|
+
"y = np.array([[99],\n",
|
1016
|
+
" [99]])\n",
|
1017
|
+
"np.hstack([grid, y])"
|
1018
|
+
]
|
1019
|
+
},
|
1020
|
+
{
|
1021
|
+
"cell_type": "code",
|
1022
|
+
"execution_count": 53,
|
1023
|
+
"id": "06bb0fec",
|
1024
|
+
"metadata": {},
|
1025
|
+
"outputs": [
|
1026
|
+
{
|
1027
|
+
"name": "stdout",
|
1028
|
+
"output_type": "stream",
|
1029
|
+
"text": [
|
1030
|
+
"[1 2 3] [99 99] [3 2 1]\n"
|
1031
|
+
]
|
1032
|
+
}
|
1033
|
+
],
|
1034
|
+
"source": [
|
1035
|
+
"#Splitting of arrays\n",
|
1036
|
+
"x = [1, 2, 3, 99, 99, 3, 2, 1]\n",
|
1037
|
+
"x1, x2, x3 = np.split(x, [3, 5])\n",
|
1038
|
+
"print(x1, x2, x3)\n"
|
1039
|
+
]
|
1040
|
+
},
|
1041
|
+
{
|
1042
|
+
"cell_type": "code",
|
1043
|
+
"execution_count": 54,
|
1044
|
+
"id": "701312e9",
|
1045
|
+
"metadata": {},
|
1046
|
+
"outputs": [
|
1047
|
+
{
|
1048
|
+
"data": {
|
1049
|
+
"text/plain": [
|
1050
|
+
"array([[ 0, 1, 2, 3],\n",
|
1051
|
+
" [ 4, 5, 6, 7],\n",
|
1052
|
+
" [ 8, 9, 10, 11],\n",
|
1053
|
+
" [12, 13, 14, 15]])"
|
1054
|
+
]
|
1055
|
+
},
|
1056
|
+
"execution_count": 54,
|
1057
|
+
"metadata": {},
|
1058
|
+
"output_type": "execute_result"
|
1059
|
+
}
|
1060
|
+
],
|
1061
|
+
"source": [
|
1062
|
+
"grid = np.arange(16).reshape((4, 4))\n",
|
1063
|
+
"grid"
|
1064
|
+
]
|
1065
|
+
},
|
1066
|
+
{
|
1067
|
+
"cell_type": "code",
|
1068
|
+
"execution_count": 55,
|
1069
|
+
"id": "976b4aef",
|
1070
|
+
"metadata": {},
|
1071
|
+
"outputs": [
|
1072
|
+
{
|
1073
|
+
"name": "stdout",
|
1074
|
+
"output_type": "stream",
|
1075
|
+
"text": [
|
1076
|
+
"[[0 1 2 3]\n",
|
1077
|
+
" [4 5 6 7]]\n",
|
1078
|
+
"[[ 8 9 10 11]\n",
|
1079
|
+
" [12 13 14 15]]\n"
|
1080
|
+
]
|
1081
|
+
}
|
1082
|
+
],
|
1083
|
+
"source": [
|
1084
|
+
"upper, lower = np.vsplit(grid, [2])\n",
|
1085
|
+
"print(upper)\n",
|
1086
|
+
"print(lower)"
|
1087
|
+
]
|
1088
|
+
},
|
1089
|
+
{
|
1090
|
+
"cell_type": "code",
|
1091
|
+
"execution_count": 56,
|
1092
|
+
"id": "3e4cdfb1",
|
1093
|
+
"metadata": {},
|
1094
|
+
"outputs": [
|
1095
|
+
{
|
1096
|
+
"name": "stdout",
|
1097
|
+
"output_type": "stream",
|
1098
|
+
"text": [
|
1099
|
+
"[[ 0 1]\n",
|
1100
|
+
" [ 4 5]\n",
|
1101
|
+
" [ 8 9]\n",
|
1102
|
+
" [12 13]]\n",
|
1103
|
+
"[[ 2 3]\n",
|
1104
|
+
" [ 6 7]\n",
|
1105
|
+
" [10 11]\n",
|
1106
|
+
" [14 15]]\n"
|
1107
|
+
]
|
1108
|
+
}
|
1109
|
+
],
|
1110
|
+
"source": [
|
1111
|
+
"left, right = np.hsplit(grid, [2])\n",
|
1112
|
+
"print(left)\n",
|
1113
|
+
"print(right)\n"
|
1114
|
+
]
|
1115
|
+
},
|
1116
|
+
{
|
1117
|
+
"cell_type": "code",
|
1118
|
+
"execution_count": null,
|
1119
|
+
"id": "11232c91",
|
1120
|
+
"metadata": {},
|
1121
|
+
"outputs": [],
|
1122
|
+
"source": []
|
1123
|
+
}
|
1124
|
+
],
|
1125
|
+
"metadata": {
|
1126
|
+
"kernelspec": {
|
1127
|
+
"display_name": "Python 3 (ipykernel)",
|
1128
|
+
"language": "python",
|
1129
|
+
"name": "python3"
|
1130
|
+
},
|
1131
|
+
"language_info": {
|
1132
|
+
"codemirror_mode": {
|
1133
|
+
"name": "ipython",
|
1134
|
+
"version": 3
|
1135
|
+
},
|
1136
|
+
"file_extension": ".py",
|
1137
|
+
"mimetype": "text/x-python",
|
1138
|
+
"name": "python",
|
1139
|
+
"nbconvert_exporter": "python",
|
1140
|
+
"pygments_lexer": "ipython3",
|
1141
|
+
"version": "3.9.13"
|
1142
|
+
}
|
1143
|
+
},
|
1144
|
+
"nbformat": 4,
|
1145
|
+
"nbformat_minor": 5
|
1146
|
+
}
|