SlideShare a Scribd company logo
1 of 77
Download to read offline
Scientific Computing with Python
- NumPy
2017/08/03 (Thus.)
WeiYuan
site: v123582.github.io
line: weiwei63
§ 全端⼯程師 + 資料科學家
略懂⼀點網站前後端開發技術,學過資料探勘與機器
學習的⽪⽑。平時熱愛參與技術社群聚會及貢獻開源
程式的樂趣。
Outline
§ About NumPy
§ Ndarray
§ Create a new Array
§ Property of Array
§ Operation of Array
§ Matrix
§ Advanced Usages
3
Outline
§ About NumPy
§ Ndarray
§ Create a new Array
§ Property of Array
§ Operation of Array
§ Matrix
§ Advanced Usages
4
the Ecosystem of Python
5Reference:	https://www.edureka.co/blog/why-you-should-choose-python-for-big-data
6Reference:	https://www.slideshare.net/gabrielspmoreira/python-for-data-science-python-brasil-11-2015
About NumPy
§ NumPy is the fundamental package for scientific computing
with Python. It contains among other things:
• a powerful N-dimensional array object
• sophisticated (broadcasting) functions
• tools for integrating C/C++ and Fortran code
• useful linear algebra, Fourier transform, and random number
capabilities
• be used as an efficient multi-dimensional container of generic data.
7
About NumPy
§ NumPy is the fundamental package for scientific computing
with Python. It contains among other things:
• a powerful N-dimensional array object
• sophisticated (broadcasting) functions
• tools for integrating C/C++ and Fortran code
• useful linear algebra, Fourier transform, and random number
capabilities
• be used as an efficient multi-dimensional container of generic data.
8
Try it!
§ #練習:Import the numpy package under the name np
9
Try it!
§ #練習:Print the numpy version and the configuration
10
Outline
§ About NumPy
§ Ndarray
§ Create a new Array
§ Property of Array
§ Operation of Array
§ Matrix
§ Advanced Usages
11
Ndarray
§ shape
§ ndim
§ dtype
§ size
§ itemsize
§ data
12
1
2
3
4
5
6
7
8
9
10
11
12
from numpy import *
a = array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]
])
Ndarray
§ shape
§ ndim
§ dtype
§ size
§ itemsize
§ data
13
1
2
3
4
5
6
7
8
9
10
11
12
from numpy import *
a = array([[ 0, 1, 2, 3, 4],
[ 5, 6, 7, 8, 9],
[10, 11, 12, 13, 14]
])
a.shape # (3, 5)
a.ndim # 2
a.dtype.name # 'int32’
a.size # 15
a.itemsize # 4
type(a) # numpy.ndarray
Outline
§ About NumPy
§ Ndarray
§ Create a new Array
§ Property of Array
§ Operation of Array
§ Matrix
§ Advanced Usages
14
Create a new Ndarray
§ One Dimension Array (1dnarray)
§ Multiple Dimension Array (ndarray)
§ Zeros, Ones, Empty
§ arange and linspace
§ random array
§ array from list/tuple
15
Create a new Ndarray
§ One Dimension Array (1dnarray)
16
1
2
3
4
5
6
7
8
9
import numpy as np
arr1 = np.array([0, 1, 2, 3, 4]) # array([0 1 2 3 4])
type(arr1) # <type 'numpy.ndarray'>
arr1.dtype # dtype('int64')
array( )
Create a new Ndarray
§ One Dimension Array (1dnarray)
17
1
2
3
4
5
6
7
8
9
import numpy as np
arr1 = np.array([0, 1, 2, 3, 4]) # array([0 1 2 3 4])
type(arr1) # <type 'numpy.ndarray'>
arr1.dtype # dtype('int64')
arr2 = np.array([1.2, 2.4, 3.6]) # array([1.2, 2.4, 3.6])
type(arr2) # <type 'numpy.ndarray'>
arr2.dtype # dtype('float64')
array( )
Create a new Ndarray
§ Question:How to assign data type for an array ?
18
Create a new Ndarray
§ Multiple Dimension Array (ndarray)
19
1
2
3
4
5
6
7
8
9
import numpy as np
a = np.array([[1, 2, 3], [4, 5, 6]])
# array([[1, 2, 3],
# [4, 5, 6]])
array( )
Create a new Ndarray
§ Question:How to change shape from 1-d array ?
20
Create a new Ndarray
§ Zeros, Ones, Empty
21
1
2
3
4
5
6
7
8
9
import numpy as np
zeros = np.zeros(5)
# array([ 0., 0., 0., 0., 0.])
zeros( )
Create a new Ndarray
§ Zeros, Ones, Empty
22
1
2
3
4
5
6
7
8
9
import numpy as np
zeros = np.ones(5)
# array([ 1., 1., 1., 1., 1.])
ones( )
Create a new Ndarray
§ Zeros, Ones, Empty
23
1
2
3
4
5
6
7
8
9
import numpy as np
zeros = np.empty(5)
# array([ 0., 0., 0., 0., 0.])
empty( )
Create a new Ndarray
§ arange and linspace
24
1
2
3
4
5
6
7
8
9
import numpy as np
arange = np.arange(5)
# array([0 1 2 3 4])
arange( )
Create a new Ndarray
§ arange and linspace
25
1
2
3
4
5
6
7
8
9
import numpy as np
linspace = np.linspace(0, 4, 5)
# array([ 0., 1., 2., 3., 4.])
linspace( )
Create a new Ndarray
§ random array
26
1
2
3
4
5
6
7
8
9
import numpy as np
linspace = np.random.randint(0, 2, size=4)
# array([ 0, 1, 1, 1])
random.randint( )
Try it!
§ #練習:Create a 3x3x3 array with random values
27
Try it!
§ #練習:Find indices of non-zero elements
28
Create a new Ndarray
§ array from list/tuple
29
1
2
3
4
5
6
7
8
9
import numpy as np
x = [1,2,3]
a = np.asarray(x)
x = (1,2,3)
a = np.asarray(x)
asarray( )
Try it!
§ #練習:Create a null vector of size 10
30
Try it!
§ #練習:Create a vector with values ranging from 10 to 49
31
Try it!
§ #練習:Create a 3x3 identity matrix
32
Outline
§ About NumPy
§ Ndarray
§ Create a new Array
§ Property of Array
§ Operation of Array
§ Matrix
§ Advanced Usages
33
Property of Ndarray
§ shape
§ ndim
§ dtype
§ size
§ itemsize
§ data
34
1
2
3
4
5
6
7
8
9
10
11
12
import numpy as np
a = np.array(
[[11, 12, 13, 14, 15],
[16, 17, 18, 19, 20],
[21, 22, 23, 24, 25],
[26, 27, 28 ,29, 30],
[31, 32, 33, 34, 35]
])
Property of Ndarray
§ shape
§ ndim
§ dtype
§ size
§ itemsize
§ data
35
1
2
3
4
5
6
7
8
9
10
11
12
print(type(a))
print(a.shape)
print(a.ndim)
print(a.dtype)
print(a.size)
print(a.itemsize)
print(a.nbytes)
Try it!
§ #練習:How to find the memory size of any array
36
data type
37
§ Question:How to assign data type for an array ?
1. Set dtype with create the array
2. Change dtype function
1. Set dtype with create the array
38
1
2
3
4
5
6
7
8
9
x = numpy.array([1,2.6,3], dtype = numpy.int64)
print(x) #
print(x.dtype) #
x = numpy.array([1,2,3], dtype = numpy.float64)
print(x) #
print(x.dtype) #
array( )
2. Change dtype function
39
1
2
3
4
5
6
7
8
9
x = numpy.array([1,2.6,3], dtype = numpy.float64)
y = x.astype(numpy.int32)
print(y) # [1 2 3]
print(y.dtype)
z = y.astype(numpy.float64)
print(z) # [ 1. 2. 3.]
print(z.dtype)
astype( )
40
data shape
41
§ Question:How to change shape from 1-d array ?
1. Set multiple array with create the array
2. Assign new shape to shape property
3. Change shape function
1. Set multiple array with create the array
42
1
2
3
4
5
6
7
8
9
import numpy as np
a = np.array([[1,2,3],[4,5,6]])
a.shape # (2, 3)
array( )
2. Assign new shape to shape property
43
1
2
3
4
5
6
7
8
9
a = np.array([[1,2,3],[4,5,6]])
a.shape = (3,2)
a # [[1, 2], [3, 4], [5, 6]]
array( )
3. Change shape function
44
1
2
3
4
5
6
7
8
9
a = np.array([[1,2,3],[4,5,6]])
b = a.reshape(3,2)
b # [[1, 2], [3, 4], [5, 6]]
reshape( )
3. Change shape function
45
1
2
3
4
5
6
7
8
9
a = np.array([[1,2,3],[4,5,6]])
b = a.reshape(3,2)
b # [[1, 2], [3, 4], [5, 6]]
a.resize(3,2)
a # [[1, 2], [3, 4], [5, 6]]
resize( )
Try it!
§ #練習:Create a 3x3 matrix with values ranging from 0 to 8
46
index and slicing
§ index
§ slicing
47
1
2
3
4
array[0] # 0
array[1] # 1
array[-1] # 4
1
2
3
4
5
array[1:3] # [1, 2]
array[:4] # [0, 1, 3]
array[3:] # [3, 4]
array[1:4:2] # [1, 3]
array[::-1] # [4, 3, 2, 1, 0]
([0,	1,	2,	3,	4])
index and slicing
§ index
§ slicing
48
1
2
3
4
array[1] # [0, 1]
array[1][0] # 0
array[1][1] # 1
array[2][0] # 2
1
2
3
4
5
array[0:2] # [[0, 1], [2, 3]]
array[:2] # [[0, 1], [2, 3]]
array[2:] # [[4, 5]]
(	[0,	1,	0,	1,	0],
[2,	3,	2,	3,	2],
[4,	5,	4,	5,	4]	)
index and slicing
§ slicing
49
1
2
3
4
array[0, 1:4] # [1, 0, 1]
array[[0, 0, 0], [1, 2, 3]]
array[1:3, 0] # [1, 3, 5]
array[[1, 2], [0, 0, 0]]
(	[0,	1,	0,	1,	0],
[2,	3,	2,	3,	2],
[4,	5,	4,	5,	4]	)
Try it!
§ #練習:Create a null vector of size 10 but the fifth value which
is 1
50
Try it!
§ #練習:Reverse a vector (first element becomes last)
51
Try it!
§ #練習:Create a 2d array with 1 on the border and 0 inside
52
Try it!
§ #練習:Create a 8x8 matrix and fill it with a checkerboard
pattern
53
Try it!
§ #練習:
54
1
2
3
4
5
6
7
8
9
import numpy as np
a = np.array([[1,2,3],[3,4,5],[4,5,6]])
# 第二列元素
# 第二行元素
# 除了第二列的元素
Try it!
§ #練習:
55
1
2
3
4
array[::2,::2]
array[:, 1]
Outline
§ About NumPy
§ Ndarray
§ Create a new Array
§ Property of Array
§ Operation of Array
§ Matrix
§ Advanced Usages
56
Basic Operators
57
sophisticated (broadcasting)
58
ufunc
59
staticstic
60
Outline
§ About NumPy
§ Ndarray
§ Create a new Array
§ Property of Array
§ Operation of Array
§ Matrix
§ Advanced Usages
61
2d-array
62
Matrix
63
2d-array vs Matrix
64
Outline
§ About NumPy
§ Ndarray
§ Create a new Array
§ Property of Array
§ Operation of Array
§ Matrix
§ Advanced Usages
65
Advanced Usages
§ Boolean indexing and Fancy indexing
§ Boolean masking
§ Incomplete Indexing
§ Where function
§ Customize dtype
66
Thanks for listening.
2017/08/03 (Thus.) Scientific Computing with Python – NumPy
Wei-Yuan Chang
v123582@gmail.com
v123582.github.io
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan

More Related Content

What's hot

String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20myrajendra
 
Python strings presentation
Python strings presentationPython strings presentation
Python strings presentationVedaGayathri1
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsPhoenix
 
Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanKavita Ganesan
 
Data Analysis and Statistics in Python using pandas and statsmodels
Data Analysis and Statistics in Python using pandas and statsmodelsData Analysis and Statistics in Python using pandas and statsmodels
Data Analysis and Statistics in Python using pandas and statsmodelsWes McKinney
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlibPiyush rai
 
Presentation on data preparation with pandas
Presentation on data preparation with pandasPresentation on data preparation with pandas
Presentation on data preparation with pandasAkshitaKanther
 
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...Edureka!
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaEdureka!
 

What's hot (20)

Python pandas Library
Python pandas LibraryPython pandas Library
Python pandas Library
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20
 
Python strings presentation
Python strings presentationPython strings presentation
Python strings presentation
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
 
Pandas
PandasPandas
Pandas
 
Numpy Talk at SIAM
Numpy Talk at SIAMNumpy Talk at SIAM
Numpy Talk at SIAM
 
Introduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita GanesanIntroduction to Java Strings, By Kavita Ganesan
Introduction to Java Strings, By Kavita Ganesan
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 
Data Analysis and Statistics in Python using pandas and statsmodels
Data Analysis and Statistics in Python using pandas and statsmodelsData Analysis and Statistics in Python using pandas and statsmodels
Data Analysis and Statistics in Python using pandas and statsmodels
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
Numpy
NumpyNumpy
Numpy
 
Presentation on data preparation with pandas
Presentation on data preparation with pandasPresentation on data preparation with pandas
Presentation on data preparation with pandas
 
NUMPY
NUMPY NUMPY
NUMPY
 
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
What are Data structures in Python? | List, Dictionary, Tuple Explained | Edu...
 
Python strings
Python stringsPython strings
Python strings
 
Data Analysis packages
Data Analysis packagesData Analysis packages
Data Analysis packages
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
 

Similar to Scientific Computing with Python - NumPy | WeiYuan

Essential numpy before you start your Machine Learning journey in python.pdf
Essential numpy before you start your Machine Learning journey in python.pdfEssential numpy before you start your Machine Learning journey in python.pdf
Essential numpy before you start your Machine Learning journey in python.pdfSmrati Kumar Katiyar
 
NUMPY [Autosaved] .pptx
NUMPY [Autosaved]                    .pptxNUMPY [Autosaved]                    .pptx
NUMPY [Autosaved] .pptxcoolmanbalu123
 
Data Manipulation with Numpy and Pandas in PythonStarting with N
Data Manipulation with Numpy and Pandas in PythonStarting with NData Manipulation with Numpy and Pandas in PythonStarting with N
Data Manipulation with Numpy and Pandas in PythonStarting with NOllieShoresna
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesAndrew Ferlitsch
 
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...HendraPurnama31
 
Python_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdfPython_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdfAnonymousUser67
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheetZahid Hasan
 
python-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxpython-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxAkashgupta517936
 
arrays-120712074248-phpapp01
arrays-120712074248-phpapp01arrays-120712074248-phpapp01
arrays-120712074248-phpapp01Abdul Samee
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Namgee Lee
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyKimikazu Kato
 
NumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptxNumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptxJohnWilliam111370
 
Numpy_Cheat_Sheet.pdf
Numpy_Cheat_Sheet.pdfNumpy_Cheat_Sheet.pdf
Numpy_Cheat_Sheet.pdfSkyNerve
 

Similar to Scientific Computing with Python - NumPy | WeiYuan (20)

Essential numpy before you start your Machine Learning journey in python.pdf
Essential numpy before you start your Machine Learning journey in python.pdfEssential numpy before you start your Machine Learning journey in python.pdf
Essential numpy before you start your Machine Learning journey in python.pdf
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
 
NUMPY-2.pptx
NUMPY-2.pptxNUMPY-2.pptx
NUMPY-2.pptx
 
numpy.pdf
numpy.pdfnumpy.pdf
numpy.pdf
 
NUMPY [Autosaved] .pptx
NUMPY [Autosaved]                    .pptxNUMPY [Autosaved]                    .pptx
NUMPY [Autosaved] .pptx
 
Data Manipulation with Numpy and Pandas in PythonStarting with N
Data Manipulation with Numpy and Pandas in PythonStarting with NData Manipulation with Numpy and Pandas in PythonStarting with N
Data Manipulation with Numpy and Pandas in PythonStarting with N
 
14078956.ppt
14078956.ppt14078956.ppt
14078956.ppt
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning LibrariesPython - Numpy/Pandas/Matplot Machine Learning Libraries
Python - Numpy/Pandas/Matplot Machine Learning Libraries
 
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
Matplotlib adalah pustaka plotting 2D Python yang menghasilkan gambar berkual...
 
Python_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdfPython_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdf
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
 
python-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptxpython-numpyandpandas-170922144956 (1).pptx
python-numpyandpandas-170922144956 (1).pptx
 
Numpy - Array.pdf
Numpy - Array.pdfNumpy - Array.pdf
Numpy - Array.pdf
 
arrays-120712074248-phpapp01
arrays-120712074248-phpapp01arrays-120712074248-phpapp01
arrays-120712074248-phpapp01
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPy
 
NumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptxNumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptx
 
Numpy_Cheat_Sheet.pdf
Numpy_Cheat_Sheet.pdfNumpy_Cheat_Sheet.pdf
Numpy_Cheat_Sheet.pdf
 
PPS-UNIT5.ppt
PPS-UNIT5.pptPPS-UNIT5.ppt
PPS-UNIT5.ppt
 

More from Wei-Yuan Chang

Python Fundamentals - Basic
Python Fundamentals - BasicPython Fundamentals - Basic
Python Fundamentals - BasicWei-Yuan Chang
 
Data Analysis with Python - Pandas | WeiYuan
Data Analysis with Python - Pandas | WeiYuanData Analysis with Python - Pandas | WeiYuan
Data Analysis with Python - Pandas | WeiYuanWei-Yuan Chang
 
Data Crawler using Python (I) | WeiYuan
Data Crawler using Python (I) | WeiYuanData Crawler using Python (I) | WeiYuan
Data Crawler using Python (I) | WeiYuanWei-Yuan Chang
 
Learning to Use Git | WeiYuan
Learning to Use Git | WeiYuanLearning to Use Git | WeiYuan
Learning to Use Git | WeiYuanWei-Yuan Chang
 
Basic Web Development | WeiYuan
Basic Web Development | WeiYuanBasic Web Development | WeiYuan
Basic Web Development | WeiYuanWei-Yuan Chang
 
資料視覺化 - D3 的第一堂課 | WeiYuan
資料視覺化 - D3 的第一堂課 | WeiYuan資料視覺化 - D3 的第一堂課 | WeiYuan
資料視覺化 - D3 的第一堂課 | WeiYuanWei-Yuan Chang
 
JavaScript Beginner Tutorial | WeiYuan
JavaScript Beginner Tutorial | WeiYuanJavaScript Beginner Tutorial | WeiYuan
JavaScript Beginner Tutorial | WeiYuanWei-Yuan Chang
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanWei-Yuan Chang
 
Introduce to PredictionIO
Introduce to PredictionIOIntroduce to PredictionIO
Introduce to PredictionIOWei-Yuan Chang
 
Analysis and Classification of Respiratory Health Risks with Respect to Air P...
Analysis and Classification of Respiratory Health Risks with Respect to Air P...Analysis and Classification of Respiratory Health Risks with Respect to Air P...
Analysis and Classification of Respiratory Health Risks with Respect to Air P...Wei-Yuan Chang
 
Forecasting Fine Grained Air Quality Based on Big Data
Forecasting Fine Grained Air Quality Based on Big DataForecasting Fine Grained Air Quality Based on Big Data
Forecasting Fine Grained Air Quality Based on Big DataWei-Yuan Chang
 
On the Coverage of Science in the Media a Big Data Study on the Impact of th...
On the Coverage of Science in the Media a Big Data Study on the Impact of th...On the Coverage of Science in the Media a Big Data Study on the Impact of th...
On the Coverage of Science in the Media a Big Data Study on the Impact of th...Wei-Yuan Chang
 
On the Ground Validation of Online Diagnosis with Twitter and Medical Records
On the Ground Validation of Online Diagnosis with Twitter and Medical RecordsOn the Ground Validation of Online Diagnosis with Twitter and Medical Records
On the Ground Validation of Online Diagnosis with Twitter and Medical RecordsWei-Yuan Chang
 
Effective Event Identification in Social Media
Effective Event Identification in Social MediaEffective Event Identification in Social Media
Effective Event Identification in Social MediaWei-Yuan Chang
 
Eears (earthquake alert and report system) a real time decision support syst...
Eears (earthquake alert and report system)  a real time decision support syst...Eears (earthquake alert and report system)  a real time decision support syst...
Eears (earthquake alert and report system) a real time decision support syst...Wei-Yuan Chang
 
Fine Grained Location Extraction from Tweets with Temporal Awareness
Fine Grained Location Extraction from Tweets with Temporal AwarenessFine Grained Location Extraction from Tweets with Temporal Awareness
Fine Grained Location Extraction from Tweets with Temporal AwarenessWei-Yuan Chang
 
Practical Lessons from Predicting Clicks on Ads at Facebook
Practical Lessons from Predicting Clicks on Ads at FacebookPractical Lessons from Predicting Clicks on Ads at Facebook
Practical Lessons from Predicting Clicks on Ads at FacebookWei-Yuan Chang
 
How many folders do you really need ? Classifying email into a handful of cat...
How many folders do you really need ? Classifying email into a handful of cat...How many folders do you really need ? Classifying email into a handful of cat...
How many folders do you really need ? Classifying email into a handful of cat...Wei-Yuan Chang
 
Extending faceted search to the general web
Extending faceted search to the general webExtending faceted search to the general web
Extending faceted search to the general webWei-Yuan Chang
 
Discovering human places of interest from multimodal mobile phone data
Discovering human places of interest from multimodal mobile phone dataDiscovering human places of interest from multimodal mobile phone data
Discovering human places of interest from multimodal mobile phone dataWei-Yuan Chang
 

More from Wei-Yuan Chang (20)

Python Fundamentals - Basic
Python Fundamentals - BasicPython Fundamentals - Basic
Python Fundamentals - Basic
 
Data Analysis with Python - Pandas | WeiYuan
Data Analysis with Python - Pandas | WeiYuanData Analysis with Python - Pandas | WeiYuan
Data Analysis with Python - Pandas | WeiYuan
 
Data Crawler using Python (I) | WeiYuan
Data Crawler using Python (I) | WeiYuanData Crawler using Python (I) | WeiYuan
Data Crawler using Python (I) | WeiYuan
 
Learning to Use Git | WeiYuan
Learning to Use Git | WeiYuanLearning to Use Git | WeiYuan
Learning to Use Git | WeiYuan
 
Basic Web Development | WeiYuan
Basic Web Development | WeiYuanBasic Web Development | WeiYuan
Basic Web Development | WeiYuan
 
資料視覺化 - D3 的第一堂課 | WeiYuan
資料視覺化 - D3 的第一堂課 | WeiYuan資料視覺化 - D3 的第一堂課 | WeiYuan
資料視覺化 - D3 的第一堂課 | WeiYuan
 
JavaScript Beginner Tutorial | WeiYuan
JavaScript Beginner Tutorial | WeiYuanJavaScript Beginner Tutorial | WeiYuan
JavaScript Beginner Tutorial | WeiYuan
 
Python fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuanPython fundamentals - basic | WeiYuan
Python fundamentals - basic | WeiYuan
 
Introduce to PredictionIO
Introduce to PredictionIOIntroduce to PredictionIO
Introduce to PredictionIO
 
Analysis and Classification of Respiratory Health Risks with Respect to Air P...
Analysis and Classification of Respiratory Health Risks with Respect to Air P...Analysis and Classification of Respiratory Health Risks with Respect to Air P...
Analysis and Classification of Respiratory Health Risks with Respect to Air P...
 
Forecasting Fine Grained Air Quality Based on Big Data
Forecasting Fine Grained Air Quality Based on Big DataForecasting Fine Grained Air Quality Based on Big Data
Forecasting Fine Grained Air Quality Based on Big Data
 
On the Coverage of Science in the Media a Big Data Study on the Impact of th...
On the Coverage of Science in the Media a Big Data Study on the Impact of th...On the Coverage of Science in the Media a Big Data Study on the Impact of th...
On the Coverage of Science in the Media a Big Data Study on the Impact of th...
 
On the Ground Validation of Online Diagnosis with Twitter and Medical Records
On the Ground Validation of Online Diagnosis with Twitter and Medical RecordsOn the Ground Validation of Online Diagnosis with Twitter and Medical Records
On the Ground Validation of Online Diagnosis with Twitter and Medical Records
 
Effective Event Identification in Social Media
Effective Event Identification in Social MediaEffective Event Identification in Social Media
Effective Event Identification in Social Media
 
Eears (earthquake alert and report system) a real time decision support syst...
Eears (earthquake alert and report system)  a real time decision support syst...Eears (earthquake alert and report system)  a real time decision support syst...
Eears (earthquake alert and report system) a real time decision support syst...
 
Fine Grained Location Extraction from Tweets with Temporal Awareness
Fine Grained Location Extraction from Tweets with Temporal AwarenessFine Grained Location Extraction from Tweets with Temporal Awareness
Fine Grained Location Extraction from Tweets with Temporal Awareness
 
Practical Lessons from Predicting Clicks on Ads at Facebook
Practical Lessons from Predicting Clicks on Ads at FacebookPractical Lessons from Predicting Clicks on Ads at Facebook
Practical Lessons from Predicting Clicks on Ads at Facebook
 
How many folders do you really need ? Classifying email into a handful of cat...
How many folders do you really need ? Classifying email into a handful of cat...How many folders do you really need ? Classifying email into a handful of cat...
How many folders do you really need ? Classifying email into a handful of cat...
 
Extending faceted search to the general web
Extending faceted search to the general webExtending faceted search to the general web
Extending faceted search to the general web
 
Discovering human places of interest from multimodal mobile phone data
Discovering human places of interest from multimodal mobile phone dataDiscovering human places of interest from multimodal mobile phone data
Discovering human places of interest from multimodal mobile phone data
 

Recently uploaded

毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhijennyeacort
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPTBoston Institute of Analytics
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024thyngster
 
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degreeyuu sss
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样vhwb25kk
 
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...Amil Baba Dawood bangali
 
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfBoston Institute of Analytics
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一F La
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort servicejennyeacort
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
办理学位证加利福尼亚大学洛杉矶分校毕业证,UCLA成绩单原版一比一
办理学位证加利福尼亚大学洛杉矶分校毕业证,UCLA成绩单原版一比一办理学位证加利福尼亚大学洛杉矶分校毕业证,UCLA成绩单原版一比一
办理学位证加利福尼亚大学洛杉矶分校毕业证,UCLA成绩单原版一比一F sss
 
毕业文凭制作#回国入职#diploma#degree美国加州州立大学北岭分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#de...
毕业文凭制作#回国入职#diploma#degree美国加州州立大学北岭分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#de...毕业文凭制作#回国入职#diploma#degree美国加州州立大学北岭分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#de...
毕业文凭制作#回国入职#diploma#degree美国加州州立大学北岭分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#de...ttt fff
 
IMA MSN - Medical Students Network (2).pptx
IMA MSN - Medical Students Network (2).pptxIMA MSN - Medical Students Network (2).pptx
IMA MSN - Medical Students Network (2).pptxdolaknnilon
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectBoston Institute of Analytics
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxMike Bennett
 
Business Analytics using Microsoft Excel
Business Analytics using Microsoft ExcelBusiness Analytics using Microsoft Excel
Business Analytics using Microsoft Excelysmaelreyes
 
MK KOMUNIKASI DATA (TI)komdat komdat.docx
MK KOMUNIKASI DATA (TI)komdat komdat.docxMK KOMUNIKASI DATA (TI)komdat komdat.docx
MK KOMUNIKASI DATA (TI)komdat komdat.docxUnduhUnggah1
 

Recently uploaded (20)

毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝DelhiRS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
RS 9000 Call In girls Dwarka Mor (DELHI)⇛9711147426🔝Delhi
 
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default  Presentation : Data Analysis Project PPTPredictive Analysis for Loan Default  Presentation : Data Analysis Project PPT
Predictive Analysis for Loan Default Presentation : Data Analysis Project PPT
 
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
Consent & Privacy Signals on Google *Pixels* - MeasureCamp Amsterdam 2024
 
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
办美国阿肯色大学小石城分校毕业证成绩单pdf电子版制作修改#真实留信入库#永久存档#真实可查#diploma#degree
 
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
1:1定制(UQ毕业证)昆士兰大学毕业证成绩单修改留信学历认证原版一模一样
 
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
NO1 Certified Black Magic Specialist Expert Amil baba in Lahore Islamabad Raw...
 
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
办理(Vancouver毕业证书)加拿大温哥华岛大学毕业证成绩单原版一比一
 
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
9711147426✨Call In girls Gurgaon Sector 31. SCO 25 escort service
 
DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
办理学位证加利福尼亚大学洛杉矶分校毕业证,UCLA成绩单原版一比一
办理学位证加利福尼亚大学洛杉矶分校毕业证,UCLA成绩单原版一比一办理学位证加利福尼亚大学洛杉矶分校毕业证,UCLA成绩单原版一比一
办理学位证加利福尼亚大学洛杉矶分校毕业证,UCLA成绩单原版一比一
 
毕业文凭制作#回国入职#diploma#degree美国加州州立大学北岭分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#de...
毕业文凭制作#回国入职#diploma#degree美国加州州立大学北岭分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#de...毕业文凭制作#回国入职#diploma#degree美国加州州立大学北岭分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#de...
毕业文凭制作#回国入职#diploma#degree美国加州州立大学北岭分校毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#de...
 
IMA MSN - Medical Students Network (2).pptx
IMA MSN - Medical Students Network (2).pptxIMA MSN - Medical Students Network (2).pptx
IMA MSN - Medical Students Network (2).pptx
 
Heart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis ProjectHeart Disease Classification Report: A Data Analysis Project
Heart Disease Classification Report: A Data Analysis Project
 
Semantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptxSemantic Shed - Squashing and Squeezing.pptx
Semantic Shed - Squashing and Squeezing.pptx
 
Business Analytics using Microsoft Excel
Business Analytics using Microsoft ExcelBusiness Analytics using Microsoft Excel
Business Analytics using Microsoft Excel
 
MK KOMUNIKASI DATA (TI)komdat komdat.docx
MK KOMUNIKASI DATA (TI)komdat komdat.docxMK KOMUNIKASI DATA (TI)komdat komdat.docx
MK KOMUNIKASI DATA (TI)komdat komdat.docx
 

Scientific Computing with Python - NumPy | WeiYuan

  • 1. Scientific Computing with Python - NumPy 2017/08/03 (Thus.) WeiYuan
  • 2. site: v123582.github.io line: weiwei63 § 全端⼯程師 + 資料科學家 略懂⼀點網站前後端開發技術,學過資料探勘與機器 學習的⽪⽑。平時熱愛參與技術社群聚會及貢獻開源 程式的樂趣。
  • 3. Outline § About NumPy § Ndarray § Create a new Array § Property of Array § Operation of Array § Matrix § Advanced Usages 3
  • 4. Outline § About NumPy § Ndarray § Create a new Array § Property of Array § Operation of Array § Matrix § Advanced Usages 4
  • 5. the Ecosystem of Python 5Reference: https://www.edureka.co/blog/why-you-should-choose-python-for-big-data
  • 7. About NumPy § NumPy is the fundamental package for scientific computing with Python. It contains among other things: • a powerful N-dimensional array object • sophisticated (broadcasting) functions • tools for integrating C/C++ and Fortran code • useful linear algebra, Fourier transform, and random number capabilities • be used as an efficient multi-dimensional container of generic data. 7
  • 8. About NumPy § NumPy is the fundamental package for scientific computing with Python. It contains among other things: • a powerful N-dimensional array object • sophisticated (broadcasting) functions • tools for integrating C/C++ and Fortran code • useful linear algebra, Fourier transform, and random number capabilities • be used as an efficient multi-dimensional container of generic data. 8
  • 9. Try it! § #練習:Import the numpy package under the name np 9
  • 10. Try it! § #練習:Print the numpy version and the configuration 10
  • 11. Outline § About NumPy § Ndarray § Create a new Array § Property of Array § Operation of Array § Matrix § Advanced Usages 11
  • 12. Ndarray § shape § ndim § dtype § size § itemsize § data 12 1 2 3 4 5 6 7 8 9 10 11 12 from numpy import * a = array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14] ])
  • 13. Ndarray § shape § ndim § dtype § size § itemsize § data 13 1 2 3 4 5 6 7 8 9 10 11 12 from numpy import * a = array([[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12, 13, 14] ]) a.shape # (3, 5) a.ndim # 2 a.dtype.name # 'int32’ a.size # 15 a.itemsize # 4 type(a) # numpy.ndarray
  • 14. Outline § About NumPy § Ndarray § Create a new Array § Property of Array § Operation of Array § Matrix § Advanced Usages 14
  • 15. Create a new Ndarray § One Dimension Array (1dnarray) § Multiple Dimension Array (ndarray) § Zeros, Ones, Empty § arange and linspace § random array § array from list/tuple 15
  • 16. Create a new Ndarray § One Dimension Array (1dnarray) 16 1 2 3 4 5 6 7 8 9 import numpy as np arr1 = np.array([0, 1, 2, 3, 4]) # array([0 1 2 3 4]) type(arr1) # <type 'numpy.ndarray'> arr1.dtype # dtype('int64') array( )
  • 17. Create a new Ndarray § One Dimension Array (1dnarray) 17 1 2 3 4 5 6 7 8 9 import numpy as np arr1 = np.array([0, 1, 2, 3, 4]) # array([0 1 2 3 4]) type(arr1) # <type 'numpy.ndarray'> arr1.dtype # dtype('int64') arr2 = np.array([1.2, 2.4, 3.6]) # array([1.2, 2.4, 3.6]) type(arr2) # <type 'numpy.ndarray'> arr2.dtype # dtype('float64') array( )
  • 18. Create a new Ndarray § Question:How to assign data type for an array ? 18
  • 19. Create a new Ndarray § Multiple Dimension Array (ndarray) 19 1 2 3 4 5 6 7 8 9 import numpy as np a = np.array([[1, 2, 3], [4, 5, 6]]) # array([[1, 2, 3], # [4, 5, 6]]) array( )
  • 20. Create a new Ndarray § Question:How to change shape from 1-d array ? 20
  • 21. Create a new Ndarray § Zeros, Ones, Empty 21 1 2 3 4 5 6 7 8 9 import numpy as np zeros = np.zeros(5) # array([ 0., 0., 0., 0., 0.]) zeros( )
  • 22. Create a new Ndarray § Zeros, Ones, Empty 22 1 2 3 4 5 6 7 8 9 import numpy as np zeros = np.ones(5) # array([ 1., 1., 1., 1., 1.]) ones( )
  • 23. Create a new Ndarray § Zeros, Ones, Empty 23 1 2 3 4 5 6 7 8 9 import numpy as np zeros = np.empty(5) # array([ 0., 0., 0., 0., 0.]) empty( )
  • 24. Create a new Ndarray § arange and linspace 24 1 2 3 4 5 6 7 8 9 import numpy as np arange = np.arange(5) # array([0 1 2 3 4]) arange( )
  • 25. Create a new Ndarray § arange and linspace 25 1 2 3 4 5 6 7 8 9 import numpy as np linspace = np.linspace(0, 4, 5) # array([ 0., 1., 2., 3., 4.]) linspace( )
  • 26. Create a new Ndarray § random array 26 1 2 3 4 5 6 7 8 9 import numpy as np linspace = np.random.randint(0, 2, size=4) # array([ 0, 1, 1, 1]) random.randint( )
  • 27. Try it! § #練習:Create a 3x3x3 array with random values 27
  • 28. Try it! § #練習:Find indices of non-zero elements 28
  • 29. Create a new Ndarray § array from list/tuple 29 1 2 3 4 5 6 7 8 9 import numpy as np x = [1,2,3] a = np.asarray(x) x = (1,2,3) a = np.asarray(x) asarray( )
  • 30. Try it! § #練習:Create a null vector of size 10 30
  • 31. Try it! § #練習:Create a vector with values ranging from 10 to 49 31
  • 32. Try it! § #練習:Create a 3x3 identity matrix 32
  • 33. Outline § About NumPy § Ndarray § Create a new Array § Property of Array § Operation of Array § Matrix § Advanced Usages 33
  • 34. Property of Ndarray § shape § ndim § dtype § size § itemsize § data 34 1 2 3 4 5 6 7 8 9 10 11 12 import numpy as np a = np.array( [[11, 12, 13, 14, 15], [16, 17, 18, 19, 20], [21, 22, 23, 24, 25], [26, 27, 28 ,29, 30], [31, 32, 33, 34, 35] ])
  • 35. Property of Ndarray § shape § ndim § dtype § size § itemsize § data 35 1 2 3 4 5 6 7 8 9 10 11 12 print(type(a)) print(a.shape) print(a.ndim) print(a.dtype) print(a.size) print(a.itemsize) print(a.nbytes)
  • 36. Try it! § #練習:How to find the memory size of any array 36
  • 37. data type 37 § Question:How to assign data type for an array ? 1. Set dtype with create the array 2. Change dtype function
  • 38. 1. Set dtype with create the array 38 1 2 3 4 5 6 7 8 9 x = numpy.array([1,2.6,3], dtype = numpy.int64) print(x) # print(x.dtype) # x = numpy.array([1,2,3], dtype = numpy.float64) print(x) # print(x.dtype) # array( )
  • 39. 2. Change dtype function 39 1 2 3 4 5 6 7 8 9 x = numpy.array([1,2.6,3], dtype = numpy.float64) y = x.astype(numpy.int32) print(y) # [1 2 3] print(y.dtype) z = y.astype(numpy.float64) print(z) # [ 1. 2. 3.] print(z.dtype) astype( )
  • 40. 40
  • 41. data shape 41 § Question:How to change shape from 1-d array ? 1. Set multiple array with create the array 2. Assign new shape to shape property 3. Change shape function
  • 42. 1. Set multiple array with create the array 42 1 2 3 4 5 6 7 8 9 import numpy as np a = np.array([[1,2,3],[4,5,6]]) a.shape # (2, 3) array( )
  • 43. 2. Assign new shape to shape property 43 1 2 3 4 5 6 7 8 9 a = np.array([[1,2,3],[4,5,6]]) a.shape = (3,2) a # [[1, 2], [3, 4], [5, 6]] array( )
  • 44. 3. Change shape function 44 1 2 3 4 5 6 7 8 9 a = np.array([[1,2,3],[4,5,6]]) b = a.reshape(3,2) b # [[1, 2], [3, 4], [5, 6]] reshape( )
  • 45. 3. Change shape function 45 1 2 3 4 5 6 7 8 9 a = np.array([[1,2,3],[4,5,6]]) b = a.reshape(3,2) b # [[1, 2], [3, 4], [5, 6]] a.resize(3,2) a # [[1, 2], [3, 4], [5, 6]] resize( )
  • 46. Try it! § #練習:Create a 3x3 matrix with values ranging from 0 to 8 46
  • 47. index and slicing § index § slicing 47 1 2 3 4 array[0] # 0 array[1] # 1 array[-1] # 4 1 2 3 4 5 array[1:3] # [1, 2] array[:4] # [0, 1, 3] array[3:] # [3, 4] array[1:4:2] # [1, 3] array[::-1] # [4, 3, 2, 1, 0] ([0, 1, 2, 3, 4])
  • 48. index and slicing § index § slicing 48 1 2 3 4 array[1] # [0, 1] array[1][0] # 0 array[1][1] # 1 array[2][0] # 2 1 2 3 4 5 array[0:2] # [[0, 1], [2, 3]] array[:2] # [[0, 1], [2, 3]] array[2:] # [[4, 5]] ( [0, 1, 0, 1, 0], [2, 3, 2, 3, 2], [4, 5, 4, 5, 4] )
  • 49. index and slicing § slicing 49 1 2 3 4 array[0, 1:4] # [1, 0, 1] array[[0, 0, 0], [1, 2, 3]] array[1:3, 0] # [1, 3, 5] array[[1, 2], [0, 0, 0]] ( [0, 1, 0, 1, 0], [2, 3, 2, 3, 2], [4, 5, 4, 5, 4] )
  • 50. Try it! § #練習:Create a null vector of size 10 but the fifth value which is 1 50
  • 51. Try it! § #練習:Reverse a vector (first element becomes last) 51
  • 52. Try it! § #練習:Create a 2d array with 1 on the border and 0 inside 52
  • 53. Try it! § #練習:Create a 8x8 matrix and fill it with a checkerboard pattern 53
  • 54. Try it! § #練習: 54 1 2 3 4 5 6 7 8 9 import numpy as np a = np.array([[1,2,3],[3,4,5],[4,5,6]]) # 第二列元素 # 第二行元素 # 除了第二列的元素
  • 56. Outline § About NumPy § Ndarray § Create a new Array § Property of Array § Operation of Array § Matrix § Advanced Usages 56
  • 61. Outline § About NumPy § Ndarray § Create a new Array § Property of Array § Operation of Array § Matrix § Advanced Usages 61
  • 65. Outline § About NumPy § Ndarray § Create a new Array § Property of Array § Operation of Array § Matrix § Advanced Usages 65
  • 66. Advanced Usages § Boolean indexing and Fancy indexing § Boolean masking § Incomplete Indexing § Where function § Customize dtype 66
  • 67. Thanks for listening. 2017/08/03 (Thus.) Scientific Computing with Python – NumPy Wei-Yuan Chang v123582@gmail.com v123582.github.io