Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit71b39c8

Browse files
authored
Add files via upload
1 parent30f0f45 commit71b39c8

File tree

2 files changed

+4178
-0
lines changed

2 files changed

+4178
-0
lines changed

‎001_Python_NumPy.ipynb

Lines changed: 375 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,375 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type":"markdown",
5+
"metadata": {},
6+
"source": [
7+
"<small><small><i>\n",
8+
"All the IPython Notebooks in this lecture series by Dr. Milan Parmar are available @ **[GitHub](https://github.com/milaan9/09_Python_NumPy_Module)**\n",
9+
"</i></small></small>"
10+
]
11+
},
12+
{
13+
"cell_type":"markdown",
14+
"metadata": {},
15+
"source": [
16+
"# Python NumPy\n",
17+
"\n",
18+
"In this class, you will learn various NumPy concepts like how to install NumPy, arrays, functions, matrix multiplication, etc. This NumPy in Python tutorial will help you learn all Python NumPy basics..\n",
19+
"\n",
20+
"**[Numpy](http://www.numpy.org/)** (‘Numerical Python’) is the core open source library for scientific computing in Python. It is a very useful library to perform mathematical and statistical operations in Python. It provides a high-performance multidimensional array object, and tools for working with these arrays. In this part, we will review the essential functions that you need to know for the tutorial on 'TensorFlow.'"
21+
]
22+
},
23+
{
24+
"cell_type":"markdown",
25+
"metadata": {},
26+
"source": [
27+
"## Why use NumPy?\n",
28+
"\n",
29+
"NumPy is memory efficiency, meaning it can handle the vast amount of data more accessible than any other library. Besides, NumPy is very convenient to work with, especially for matrix multiplication and reshaping. On top of that, NumPy is fast. In fact, TensorFlow and Scikit learn to use NumPy array to compute the matrix multiplication in the back end."
30+
]
31+
},
32+
{
33+
"cell_type":"markdown",
34+
"metadata": {},
35+
"source": [
36+
"## Python NumPy Array:\n",
37+
"\n",
38+
"A numpy array is a grid of values, all of the same type, and is indexed by a tuple of nonnegative integers. The number of dimensions is the rank of the array; the shape of an array is a tuple of integers giving the size of the array along each dimension.\n",
39+
"\n",
40+
"Numpy array is a powerful N-dimensional array object which is in the form of rows and columns. We can initialize NumPy arrays from nested Python lists and access it elements."
41+
]
42+
},
43+
{
44+
"cell_type":"markdown",
45+
"metadata": {},
46+
"source": [
47+
"## How to Install NumPy?\n",
48+
"\n",
49+
"NumPy is installed by default with Anaconda.\n",
50+
"\n",
51+
"In remote case, NumPy not installed-\n",
52+
"\n",
53+
"You can install NumPy using Anaconda:\n",
54+
"\n",
55+
"```puthon\n",
56+
"conda install -c anaconda numpy\t\t\n",
57+
"```\n",
58+
"In Jupyter Notebook :\n",
59+
"\n",
60+
"```python\n",
61+
">>> import sys\n",
62+
">>> !conda install --yes --prefix {sys.prefix} numpy\n",
63+
"```"
64+
]
65+
},
66+
{
67+
"cell_type":"markdown",
68+
"metadata": {
69+
"heading_collapsed":true
70+
},
71+
"source": [
72+
"### Import NumPy and Check Version\n",
73+
"\n",
74+
"The command to import numpy is\n",
75+
"\n",
76+
"```python\n",
77+
"import numpy as np\n",
78+
"```\n",
79+
"Above code renames the Numpy namespace to np. This permits us to prefix Numpy function, methods, and attributes with\" np\" instead of typing\" numpy.\" It is the standard shortcut you will find in the numpy literature"
80+
]
81+
},
82+
{
83+
"cell_type":"code",
84+
"execution_count":null,
85+
"metadata": {
86+
"ExecuteTime": {
87+
"end_time":"2021-05-27T16:41:31.257895Z",
88+
"start_time":"2021-05-27T16:41:31.250082Z"
89+
},
90+
"hidden":true
91+
},
92+
"outputs": [],
93+
"source": [
94+
"# To check your installed version of Numpy use the command\n",
95+
"\n",
96+
"print (np.__version__)"
97+
]
98+
},
99+
{
100+
"cell_type":"markdown",
101+
"metadata": {},
102+
"source": [
103+
"# NumPy Basics"
104+
]
105+
},
106+
{
107+
"cell_type":"markdown",
108+
"metadata": {},
109+
"source": [
110+
"### NumPy Basics\n",
111+
"\n",
112+
"| Operator | Description |\n",
113+
"|:---- |:---- |\n",
114+
"| **`np.array([1,2,3])`** | **1d array** |\n",
115+
"| **`np.array([(1,2,3),(4,5,6)])`** | **2d array** |\n",
116+
"| **`np.arange(start,stop,step)`** | **range array** |"
117+
]
118+
},
119+
{
120+
"cell_type":"markdown",
121+
"metadata": {},
122+
"source": [
123+
"### Placeholders\n",
124+
"\n",
125+
"| Operator | Description |\n",
126+
"|:---- |:---- |\n",
127+
"| **`np.linspace(0,2,9)`** | **Add evenly spaced values btw interval to array of length** |\n",
128+
"| **`np.zeros((1,2))`** | **Create and array filled with zeros** |\n",
129+
"| **`np.ones((1,2))`** | **Creates an array filled with ones** |\n",
130+
"| **`np.random.random((5,5))`** | **Creates random array** |\n",
131+
"| **`np.empty((2,2))`** | **Creates an empty array** |"
132+
]
133+
},
134+
{
135+
"cell_type":"markdown",
136+
"metadata": {},
137+
"source": [
138+
"### Array\n",
139+
"\n",
140+
"| Operator | Description |\n",
141+
"|:---- |:---- |\n",
142+
"| **`array.shape`** | **Dimensions (Rows,Columns)** |\n",
143+
"| **`len(array)`** | **Length of Array** |\n",
144+
"| **`array.ndim`** | **Number of Array Dimensions** |\n",
145+
"| **`array.dtype`** | **Data Type** |\n",
146+
"| **`array.astype(type)`** | **Converts to Data Type** |\n",
147+
"| **`type(array)`** | **Type of Array** |"
148+
]
149+
},
150+
{
151+
"cell_type":"markdown",
152+
"metadata": {},
153+
"source": [
154+
"### Copying/Sorting\n",
155+
"\n",
156+
"| Operator | Description |\n",
157+
"|:---- |:---- |\n",
158+
"| **`np.copy(array)`** | **Creates copy of array** |\n",
159+
"| **`other = array.copy()`** | **Creates deep copy of array** |\n",
160+
"| **`array.sort()`** | **Sorts an array** |\n",
161+
"| **`array.sort(axis=0)`** | **Sorts axis of array** |"
162+
]
163+
},
164+
{
165+
"cell_type":"markdown",
166+
"metadata": {},
167+
"source": [
168+
"## Array Manipulation"
169+
]
170+
},
171+
{
172+
"cell_type":"markdown",
173+
"metadata": {},
174+
"source": [
175+
"### Adding or Removing Elements\n",
176+
"\n",
177+
"| Operator | Description |\n",
178+
"|:---- |:---- |\n",
179+
"| **`np.append(a,b)`** | **Append items to array** |\n",
180+
"| **`np.insert(array, 1, 2, axis)`** | **Insert items into array at axis 0 or 1** |\n",
181+
"| **`np.resize((2,4))`** | **Resize array to shape(2,4)** |\n",
182+
"| **`np.delete(array,1,axis)`** | **Deletes items from array** |"
183+
]
184+
},
185+
{
186+
"cell_type":"markdown",
187+
"metadata": {},
188+
"source": [
189+
"### Combining Arrays\n",
190+
"\n",
191+
"| Operator | Description |\n",
192+
"|:---- |:---- |\n",
193+
"| **`np.concatenate((a,b),axis=0)`** | **Split an array into multiple sub-arrays.** |\n",
194+
"| **`np.vstack((a,b))`** | **Split an array in sub-arrays of (nearly) identical size** |\n",
195+
"| **`np.hstack((a,b))`** | **Split the array horizontally at 3rd index** |"
196+
]
197+
},
198+
{
199+
"cell_type":"markdown",
200+
"metadata": {},
201+
"source": [
202+
"### More\n",
203+
"\n",
204+
"| Operator | Description |\n",
205+
"|:---- |:---- |\n",
206+
"| **`other = ndarray.flatten()`** | **Flattens a 2d array to 1d** |\n",
207+
"| **`array = np.transpose(other)`** | **Transpose array** |\n",
208+
"| **`array.T`** | **Transpose array** |\n",
209+
"| **`inverse = np.linalg.inv(matrix)`** | **Inverse of a given matrix** |"
210+
]
211+
},
212+
{
213+
"cell_type":"markdown",
214+
"metadata": {},
215+
"source": [
216+
"## Slicing and Subsetting\n",
217+
"\n",
218+
"| Operator | Description |\n",
219+
"|:---- |:---- |\n",
220+
"| **`array[i]`** | **1d array at index i** |\n",
221+
"| **`array[i,j]`** | **2d array at index[i][j]** |\n",
222+
"| **`array[i<4]`** | **Boolean Indexing, see Tricks** |\n",
223+
"| **`array[0:3]`** | **Select items of index 0, 1 and 2** |\n",
224+
"| **`array[0:2,1]`** | **Select items of rows 0 and 1 at column 1** |\n",
225+
"| **`array[:1]`** | **Select items of row 0 (equals array[0:1, :])** |\n",
226+
"| **`array[1:2, :]`** | **Select items of row 1** |\n",
227+
"| **`[comment]: <> (`** | **array[1,...]** |\n",
228+
"| **`array[ : :-1]`** | **Reverses array** |"
229+
]
230+
},
231+
{
232+
"cell_type":"markdown",
233+
"metadata": {},
234+
"source": [
235+
"## Mathematics"
236+
]
237+
},
238+
{
239+
"cell_type":"markdown",
240+
"metadata": {},
241+
"source": [
242+
"### Operations\n",
243+
"\n",
244+
"| Operator | Description |\n",
245+
"|:---- |:---- |\n",
246+
"| **`np.add(x,y)`** | **Addition** |\n",
247+
"| **`np.substract(x,y)`** | **Subtraction** |\n",
248+
"| **`np.divide(x,y)`** | **Division** |\n",
249+
"| **`np.multiply(x,y)`** | **Multiplication** |\n",
250+
"| **`np.sqrt(x)`** | **Square Root** |\n",
251+
"| **`np.sin(x)`** | **Element-wise sine** |\n",
252+
"| **`np.cos(x)`** | **Element-wise cosine** |\n",
253+
"| **`np.log(x)`** | **Element-wise natural log** |\n",
254+
"| **`np.dot(x,y)`** | **Dot product** |\n",
255+
"| **`np.roots([1,0,-4])`** | **Roots of a given polynomial coefficients** |"
256+
]
257+
},
258+
{
259+
"cell_type":"markdown",
260+
"metadata": {},
261+
"source": [
262+
"### Comparison\n",
263+
"\n",
264+
"| Operator | Description |\n",
265+
"|:----: |:---- |\n",
266+
"| **`==`** | **Equal** |\n",
267+
"| **`!=`** | **Not equal** |\n",
268+
"| **`<`** | **Smaller than** |\n",
269+
"| **`>`** | **Greater than** |\n",
270+
"| **`<=`** | **Smaller than or equal** |\n",
271+
"| **`>=`** | **Greater than or equal** |\n",
272+
"| **`np.array_equal(x,y)`** | **Array-wise comparison** |"
273+
]
274+
},
275+
{
276+
"cell_type":"markdown",
277+
"metadata": {},
278+
"source": [
279+
"## Basic Statistics\n",
280+
"\n",
281+
"| Operator | Description |\n",
282+
"|:---- |:---- |\n",
283+
"| **`np.mean(array)`** | **Mean** |\n",
284+
"| **`np.median(array)`** | **Median** |\n",
285+
"| **`array.corrcoef()`** | **Correlation Coefficient** |\n",
286+
"| **`np.std(array)`** | **Standard Deviation** |"
287+
]
288+
},
289+
{
290+
"cell_type":"markdown",
291+
"metadata": {},
292+
"source": [
293+
"### More\n",
294+
"\n",
295+
"| Operator | Description |\n",
296+
"|:---- |:---- |\n",
297+
"| **`array.sum()`** | **Array-wise sum** |\n",
298+
"| **`array.min()`** | **Array-wise minimum value** |\n",
299+
"| **`array.max(axis=0)`** | **Maximum value of specified axis** |\n",
300+
"| **`array.cumsum(axis=0)`** | **Cumulative sum of specified axis** |"
301+
]
302+
},
303+
{
304+
"cell_type":"code",
305+
"execution_count":null,
306+
"metadata": {},
307+
"outputs": [],
308+
"source": []
309+
}
310+
],
311+
"metadata": {
312+
"hide_input":false,
313+
"kernelspec": {
314+
"display_name":"Python 3",
315+
"language":"python",
316+
"name":"python3"
317+
},
318+
"language_info": {
319+
"codemirror_mode": {
320+
"name":"ipython",
321+
"version":3
322+
},
323+
"file_extension":".py",
324+
"mimetype":"text/x-python",
325+
"name":"python",
326+
"nbconvert_exporter":"python",
327+
"pygments_lexer":"ipython3",
328+
"version":"3.8.8"
329+
},
330+
"toc": {
331+
"base_numbering":1,
332+
"nav_menu": {},
333+
"number_sections":true,
334+
"sideBar":true,
335+
"skip_h1_title":false,
336+
"title_cell":"Table of Contents",
337+
"title_sidebar":"Contents",
338+
"toc_cell":false,
339+
"toc_position": {},
340+
"toc_section_display":true,
341+
"toc_window_display":false
342+
},
343+
"varInspector": {
344+
"cols": {
345+
"lenName":16,
346+
"lenType":16,
347+
"lenVar":40
348+
},
349+
"kernels_config": {
350+
"python": {
351+
"delete_cmd_postfix":"",
352+
"delete_cmd_prefix":"del",
353+
"library":"var_list.py",
354+
"varRefreshCmd":"print(var_dic_list())"
355+
},
356+
"r": {
357+
"delete_cmd_postfix":")",
358+
"delete_cmd_prefix":"rm(",
359+
"library":"var_list.r",
360+
"varRefreshCmd":"cat(var_dic_list())"
361+
}
362+
},
363+
"types_to_exclude": [
364+
"module",
365+
"function",
366+
"builtin_function_or_method",
367+
"instance",
368+
"_Feature"
369+
],
370+
"window_display":false
371+
}
372+
},
373+
"nbformat":4,
374+
"nbformat_minor":2
375+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp