SlideShare a Scribd company logo
2
Slide 2
NumPy
NumPy is an extension to the Python programming language, adding support for
large, multi-dimensional arrays and matrices, along with a large library of high-level
mathematical functions to operate on these arrays
To install NumPy run:
python setup.py install
To perform an in-place build that can be run from the source folder run:
python setup.py build_ext --inplace
The NumPy build system uses distutils and numpy.distutils. setuptools is only
used when building via pip or with python setupegg.py.
Most read
8
Slide 8
Airthmatic Operation with numpy
Most read
10
Slide 10
import numpy as np
a = np.array([[1,2,3], [4,5,6]], int) # Accept two arguments list and type
>>> b = a.reshape(3,2) # Return the new shape of array
>>> b.shape # Return (3,2)
>>> len(a) # Return length of a
>>> 2 in a # Check if 2 is available in a
>>> b.tolist() # Return [[1, 2], [3, 4], [5, 6]]
>>> list(b) # Return [array([1, 2]), array([3, 4]), array([5, 6])]
>>> c = b
>>> b[0][0] = 10
>>> c # Return array([[10, 2], [ 3, 4], [ 5, 6]])
Reshaping array
Most read
Slide 1
Objective of the class
• What is numpy?
• numpy performance test
• Introduction to numpy arrays
• Introduction to numpy function
• Dealing with Flat files using numpy
• Mathematical functions
• Statisticals function
• Operations with arrays
Introduction to Numpy
Slide 2
NumPy
NumPy is an extension to the Python programming language, adding support for
large, multi-dimensional arrays and matrices, along with a large library of high-level
mathematical functions to operate on these arrays
To install NumPy run:
python setup.py install
To perform an in-place build that can be run from the source folder run:
python setup.py build_ext --inplace
The NumPy build system uses distutils and numpy.distutils. setuptools is only
used when building via pip or with python setupegg.py.
Slide 3
Official Website: http://www.numpy.org
• NumPy is licensed under the BSD license, enabling reuse with few restrictions.
• NumPy replaces Numeric and Numarray
• Numpy was initially developed by Travis Oliphant
• There are 225+ Contributors to the project (github.com)
• NumPy 1.0 released October, 2006
• Numpy 1.14.0 is the lastest version of numpy
• There are more than 200K downloads/month from PyPI
NumPy
Slide 4
NumPy performance Test
Slide 5
Getting Started with Numpy
>>> # Importing Numpy module
>>> import numpy
>>> import numpy as np
IPython has a ‘pylab’ mode where it imports all of NumPy, Matplotlib,
and SciPy into the namespace for you as a convenience. It also enables
threading for showing plots
Slide 6
Getting Started with Numpy
• Arrays are the central feature of NumPy.
• Arrays in Python are similar to lists in Python, the only difference being the array
elements should be of the same type
import numpy as np
a = np.array([1,2,3], float) # Accept two arguments list and type
print a # Return array([ 1., 2., 3.])
print type(a) # Return <type 'numpy.ndarray'>
print a[2] # 3.0
print a.dtype # Print the element type
print a.itemsize # print bytes per element
print a.shape # print the shape of an array
print a.size # print the size of an array
Slide 7
a.nbytes # return the total bytes used by an array
a.ndim # provide the dimension of an array
a[0] = 10.5 # Modify array first index important decimal will
come if the array is float type else it will be hold only 10
a.fill(20) # Fill all the values by 20
a[1:3] # Slice the array
a[-2:] # Last two elements of an array
Getting Started with Numpy
Slide 8
Airthmatic Operation with numpy
Slide 9
import numpy as np
a = np.array([[1,2,3], [4,5,6]], int) # Accept two arguments list and type
>>> a.shape # Return (2, 3)
>>> a.ndim # return 2
>>> a[0][0] # Return 1
>>> a[0,0] # Return 1
>>> a[1,2] # Return 6
>>> a[1:] # Return array([[4, 5, 6]])
>>> a[1,:] # Return array([4, 5, 6])
>>> a[:2] # Return array([[1, 2, 3],[4, 5, 6]])
>>> a[:,2] # Return array([3, 6])
>>> a[:,1] # Return array([2, 5])
>>> a[:,0] # Return array([1, 4])
Multi-Dimensional Arrays
Slide 10
import numpy as np
a = np.array([[1,2,3], [4,5,6]], int) # Accept two arguments list and type
>>> b = a.reshape(3,2) # Return the new shape of array
>>> b.shape # Return (3,2)
>>> len(a) # Return length of a
>>> 2 in a # Check if 2 is available in a
>>> b.tolist() # Return [[1, 2], [3, 4], [5, 6]]
>>> list(b) # Return [array([1, 2]), array([3, 4]), array([5, 6])]
>>> c = b
>>> b[0][0] = 10
>>> c # Return array([[10, 2], [ 3, 4], [ 5, 6]])
Reshaping array
Slide 11
Slices Are References
>>> a = array((0,1,2,3,4))
# create a slice containing only the
# last element of a
>>> b = a[2:4]
>>> b
array([2, 3])
>>> b[0] = 10
# changing b changed a!
>>> a
array([ 0, 1, 10, 3, 4])
Slide 12
arange function and slicing
>>> a = np.arange(1,80, 2)
array([ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33,
35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67,
69, 71, 73, 75, 77, 79])
>>> a[[1,5,10]] # Return values at index 1,5 and 10
>>> myIndexes = [4,5,6]
>>> a[myIndexes] # Return values at indexes 4,5,6..
>>> mask = a % 5 == 0 # Return boolean value at those indexes
>>> a[mask]
Out[46]: array([ 5, 15, 25, 35, 45, 55, 65, 75])
Slide 13
Where function
>>> where (a % 5 == 0)
# Returns - (array([ 2, 7, 12, 17, 22, 27, 32, 37], dtype=int64),)
>>> loc = where(a % 5 == 0)
>>> print a[loc]
[ 5 15 25 35 45 55 65 75]
Slide 14
Flatten Arrays
# Create a 2D array
>>> a = array([[0,1],
[2,3]])
# Flatten out elements to 1D
>>> b = a.flatten()
>>> b
array([0,1,2,3])
# Changing b does not change a
>>> b[0] = 10
>>> b
array([10,1,2,3])
>>> a
array([[0, 1],
[2, 3]])
Slide 15
>>> a = array([[0,1,2],
... [3,4,5]])
>>> a.shape
(2,3)
# Transpose swaps the order # of axes. For 2-D this # swaps rows and columns.
>>> a.transpose()
array([[0, 3], [1, 4],[2, 5]])
# The .T attribute is # equivalent to transpose().
>>> a.T
array([[0, 3],
[1, 4],
[2, 5]])
Transpose Arrays
Slide 16
csv = np.loadtxt(r'A:UPDATE PythonModule 11Programsconstituents-
financials.csv', skiprows=1, dtype=str, delimiter=",", usecols = (3,4,5))
Arrays from/to ASCII files
Slide 17
Other format supported by other similar package

More Related Content

What's hot (20)

Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
Edureka!
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
Girish Khanzode
 
Introduction to NumPy
Introduction to NumPyIntroduction to NumPy
Introduction to NumPy
Huy Nguyen
 
Pandas
PandasPandas
Pandas
maikroeder
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
Devashish Kumar
 
Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in Python
Marc Garcia
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
EN1036VivekSingh
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
Devashish Kumar
 
Python Lambda Function
Python Lambda FunctionPython Lambda Function
Python Lambda Function
Md Soyaib
 
NUMPY
NUMPY NUMPY
NUMPY
Global Academy of Technology
 
Introduction to pandas
Introduction to pandasIntroduction to pandas
Introduction to pandas
Piyush rai
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
hydpy
 
Introduction to numpy
Introduction to numpyIntroduction to numpy
Introduction to numpy
Gaurav Aggarwal
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptx
SharmilaMore5
 
Python programming : Classes objects
Python programming : Classes objectsPython programming : Classes objects
Python programming : Classes objects
Emertxe Information Technologies Pvt Ltd
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
Emertxe Information Technologies Pvt Ltd
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
ARVIND PANDE
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Introduction to Pandas and Time Series Analysis [PyCon DE]
Introduction to Pandas and Time Series Analysis [PyCon DE]Introduction to Pandas and Time Series Analysis [PyCon DE]
Introduction to Pandas and Time Series Analysis [PyCon DE]
Alexander Hendorf
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
Edureka!
 
Introduction to NumPy
Introduction to NumPyIntroduction to NumPy
Introduction to NumPy
Huy Nguyen
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
Devashish Kumar
 
Data visualization in Python
Data visualization in PythonData visualization in Python
Data visualization in Python
Marc Garcia
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
Devashish Kumar
 
Python Lambda Function
Python Lambda FunctionPython Lambda Function
Python Lambda Function
Md Soyaib
 
Introduction to pandas
Introduction to pandasIntroduction to pandas
Introduction to pandas
Piyush rai
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
hydpy
 
Visualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptxVisualization and Matplotlib using Python.pptx
Visualization and Matplotlib using Python.pptx
SharmilaMore5
 
Python lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce functionPython lambda functions with filter, map & reduce function
Python lambda functions with filter, map & reduce function
ARVIND PANDE
 
Python Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, DictionaryPython Variable Types, List, Tuple, Dictionary
Python Variable Types, List, Tuple, Dictionary
Soba Arjun
 
Modules and packages in python
Modules and packages in pythonModules and packages in python
Modules and packages in python
TMARAGATHAM
 
Introduction to Pandas and Time Series Analysis [PyCon DE]
Introduction to Pandas and Time Series Analysis [PyCon DE]Introduction to Pandas and Time Series Analysis [PyCon DE]
Introduction to Pandas and Time Series Analysis [PyCon DE]
Alexander Hendorf
 

Similar to Introduction to numpy Session 1 (20)

ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
DineshThallapelly
 
Numpy in python, Array operations using numpy and so on
Numpy in python, Array operations using numpy and so onNumpy in python, Array operations using numpy and so on
Numpy in python, Array operations using numpy and so on
SherinRappai
 
NUMPY [Autosaved] .pptx
NUMPY [Autosaved]                    .pptxNUMPY [Autosaved]                    .pptx
NUMPY [Autosaved] .pptx
coolmanbalu123
 
NUMPY LIBRARY study materials PPT 2.pptx
NUMPY LIBRARY study materials PPT 2.pptxNUMPY LIBRARY study materials PPT 2.pptx
NUMPY LIBRARY study materials PPT 2.pptx
CHETHANKUMAR274045
 
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
tahirnaquash2
 
CAP776Numpy (2).ppt
CAP776Numpy (2).pptCAP776Numpy (2).ppt
CAP776Numpy (2).ppt
ChhaviCoachingCenter
 
CAP776Numpy.ppt
CAP776Numpy.pptCAP776Numpy.ppt
CAP776Numpy.ppt
kdr52121
 
Introduction to numpy.pptx
Introduction to numpy.pptxIntroduction to numpy.pptx
Introduction to numpy.pptx
ssuser0e701a
 
numpy code and examples with attributes.pptx
numpy code and examples with attributes.pptxnumpy code and examples with attributes.pptx
numpy code and examples with attributes.pptx
swathis752031
 
Lecture 2 _Foundions foundions NumPyI.pptx
Lecture 2 _Foundions foundions NumPyI.pptxLecture 2 _Foundions foundions NumPyI.pptx
Lecture 2 _Foundions foundions NumPyI.pptx
disserdekabrcha
 
L 5 Numpy final learning and Coding
L 5 Numpy final learning and CodingL 5 Numpy final learning and Coding
L 5 Numpy final learning and Coding
Kirti Verma
 
NUMPY-2.pptx
NUMPY-2.pptxNUMPY-2.pptx
NUMPY-2.pptx
MahendraVusa
 
Numpy ndarrays.pdf
Numpy ndarrays.pdfNumpy ndarrays.pdf
Numpy ndarrays.pdf
SudhanshiBakre1
 
Numpy
NumpyNumpy
Numpy
Jyoti shukla
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
Zahid Hasan
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
Nishant Upadhyay
 
Python_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdfPython_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdf
AnonymousUser67
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
DrJasmineBeulahG
 
lec08-numpy.pptx
lec08-numpy.pptxlec08-numpy.pptx
lec08-numpy.pptx
lekha572836
 
Data Preprocessing Introduction for Machine Learning
Data Preprocessing Introduction for Machine LearningData Preprocessing Introduction for Machine Learning
Data Preprocessing Introduction for Machine Learning
sonali sonavane
 
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
DineshThallapelly
 
Numpy in python, Array operations using numpy and so on
Numpy in python, Array operations using numpy and so onNumpy in python, Array operations using numpy and so on
Numpy in python, Array operations using numpy and so on
SherinRappai
 
NUMPY [Autosaved] .pptx
NUMPY [Autosaved]                    .pptxNUMPY [Autosaved]                    .pptx
NUMPY [Autosaved] .pptx
coolmanbalu123
 
NUMPY LIBRARY study materials PPT 2.pptx
NUMPY LIBRARY study materials PPT 2.pptxNUMPY LIBRARY study materials PPT 2.pptx
NUMPY LIBRARY study materials PPT 2.pptx
CHETHANKUMAR274045
 
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
tahirnaquash2
 
CAP776Numpy.ppt
CAP776Numpy.pptCAP776Numpy.ppt
CAP776Numpy.ppt
kdr52121
 
Introduction to numpy.pptx
Introduction to numpy.pptxIntroduction to numpy.pptx
Introduction to numpy.pptx
ssuser0e701a
 
numpy code and examples with attributes.pptx
numpy code and examples with attributes.pptxnumpy code and examples with attributes.pptx
numpy code and examples with attributes.pptx
swathis752031
 
Lecture 2 _Foundions foundions NumPyI.pptx
Lecture 2 _Foundions foundions NumPyI.pptxLecture 2 _Foundions foundions NumPyI.pptx
Lecture 2 _Foundions foundions NumPyI.pptx
disserdekabrcha
 
L 5 Numpy final learning and Coding
L 5 Numpy final learning and CodingL 5 Numpy final learning and Coding
L 5 Numpy final learning and Coding
Kirti Verma
 
Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
Zahid Hasan
 
Python_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdfPython_cheatsheet_numpy.pdf
Python_cheatsheet_numpy.pdf
AnonymousUser67
 
lec08-numpy.pptx
lec08-numpy.pptxlec08-numpy.pptx
lec08-numpy.pptx
lekha572836
 
Data Preprocessing Introduction for Machine Learning
Data Preprocessing Introduction for Machine LearningData Preprocessing Introduction for Machine Learning
Data Preprocessing Introduction for Machine Learning
sonali sonavane
 
Ad

Recently uploaded (20)

Content Moderation Services_ Leading the Future of Online Safety.docx
Content Moderation Services_ Leading the Future of Online Safety.docxContent Moderation Services_ Leading the Future of Online Safety.docx
Content Moderation Services_ Leading the Future of Online Safety.docx
sofiawilliams5966
 
Ethical Frameworks for Trustworthy AI – Opportunities for Researchers in Huma...
Ethical Frameworks for Trustworthy AI – Opportunities for Researchers in Huma...Ethical Frameworks for Trustworthy AI – Opportunities for Researchers in Huma...
Ethical Frameworks for Trustworthy AI – Opportunities for Researchers in Huma...
Karim Baïna
 
Blue Dark Professional Geometric Business Project Presentation .pdf
Blue Dark Professional Geometric Business Project Presentation .pdfBlue Dark Professional Geometric Business Project Presentation .pdf
Blue Dark Professional Geometric Business Project Presentation .pdf
mohammadhaidarayoobi
 
15 Benefits of Data Analytics in Business Growth.pdf
15 Benefits of Data Analytics in Business Growth.pdf15 Benefits of Data Analytics in Business Growth.pdf
15 Benefits of Data Analytics in Business Growth.pdf
AffinityCore
 
PSUG 7 - 2025-06-03 - David Bianco on Splunk SURGe
PSUG 7 - 2025-06-03 - David Bianco on Splunk SURGePSUG 7 - 2025-06-03 - David Bianco on Splunk SURGe
PSUG 7 - 2025-06-03 - David Bianco on Splunk SURGe
Tomas Moser
 
一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理
一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理
一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理
Taqyea
 
delta airlines new york office (Airwayscityoffice)
delta airlines new york office (Airwayscityoffice)delta airlines new york office (Airwayscityoffice)
delta airlines new york office (Airwayscityoffice)
jamespromind
 
Али махмуд to The teacm of ghsbh to fortune .pptx
Али махмуд to The teacm of ghsbh to fortune .pptxАли махмуд to The teacm of ghsbh to fortune .pptx
Али махмуд to The teacm of ghsbh to fortune .pptx
palr19411
 
9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj
9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj
9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj
aishwaryavdcw
 
egc.pdf tài liệu tiếng Anh cho học sinh THPT
egc.pdf tài liệu tiếng Anh cho học sinh THPTegc.pdf tài liệu tiếng Anh cho học sinh THPT
egc.pdf tài liệu tiếng Anh cho học sinh THPT
huyenmy200809
 
Artificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptxArtificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptx
AbhijitPal87
 
Artificial-Intelligence-in-Autonomous-Vehicles (1).pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1).pptxArtificial-Intelligence-in-Autonomous-Vehicles (1).pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1).pptx
AbhijitPal87
 
Understanding Tree Data Structure and Its Applications
Understanding Tree Data Structure and Its ApplicationsUnderstanding Tree Data Structure and Its Applications
Understanding Tree Data Structure and Its Applications
M Munim
 
llm lecture 3 stanford blah blah blah blah
llm lecture 3 stanford blah blah blah blahllm lecture 3 stanford blah blah blah blah
llm lecture 3 stanford blah blah blah blah
saud140081
 
lecture 33333222234555555555555555556.pptx
lecture 33333222234555555555555555556.pptxlecture 33333222234555555555555555556.pptx
lecture 33333222234555555555555555556.pptx
obsinaafilmakuush
 
Human body make Structure analysis the part of the human
Human body make Structure analysis the part of the humanHuman body make Structure analysis the part of the human
Human body make Structure analysis the part of the human
ankit392215
 
Comprehensive Roadmap of AI, ML, DS, DA & DSA.pdf
Comprehensive Roadmap of AI, ML, DS, DA & DSA.pdfComprehensive Roadmap of AI, ML, DS, DA & DSA.pdf
Comprehensive Roadmap of AI, ML, DS, DA & DSA.pdf
epsilonice
 
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docxHow Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
sofiawilliams5966
 
BADS-MBA-Unit 1 that what data science and Interpretation
BADS-MBA-Unit 1 that what data science and InterpretationBADS-MBA-Unit 1 that what data science and Interpretation
BADS-MBA-Unit 1 that what data science and Interpretation
srishtisingh1813
 
Data Analytics and visualization-PowerBi
Data Analytics and visualization-PowerBiData Analytics and visualization-PowerBi
Data Analytics and visualization-PowerBi
Krishnapriya975316
 
Content Moderation Services_ Leading the Future of Online Safety.docx
Content Moderation Services_ Leading the Future of Online Safety.docxContent Moderation Services_ Leading the Future of Online Safety.docx
Content Moderation Services_ Leading the Future of Online Safety.docx
sofiawilliams5966
 
Ethical Frameworks for Trustworthy AI – Opportunities for Researchers in Huma...
Ethical Frameworks for Trustworthy AI – Opportunities for Researchers in Huma...Ethical Frameworks for Trustworthy AI – Opportunities for Researchers in Huma...
Ethical Frameworks for Trustworthy AI – Opportunities for Researchers in Huma...
Karim Baïna
 
Blue Dark Professional Geometric Business Project Presentation .pdf
Blue Dark Professional Geometric Business Project Presentation .pdfBlue Dark Professional Geometric Business Project Presentation .pdf
Blue Dark Professional Geometric Business Project Presentation .pdf
mohammadhaidarayoobi
 
15 Benefits of Data Analytics in Business Growth.pdf
15 Benefits of Data Analytics in Business Growth.pdf15 Benefits of Data Analytics in Business Growth.pdf
15 Benefits of Data Analytics in Business Growth.pdf
AffinityCore
 
PSUG 7 - 2025-06-03 - David Bianco on Splunk SURGe
PSUG 7 - 2025-06-03 - David Bianco on Splunk SURGePSUG 7 - 2025-06-03 - David Bianco on Splunk SURGe
PSUG 7 - 2025-06-03 - David Bianco on Splunk SURGe
Tomas Moser
 
一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理
一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理
一比一原版(USC毕业证)南加利福尼亚大学毕业证如何办理
Taqyea
 
delta airlines new york office (Airwayscityoffice)
delta airlines new york office (Airwayscityoffice)delta airlines new york office (Airwayscityoffice)
delta airlines new york office (Airwayscityoffice)
jamespromind
 
Али махмуд to The teacm of ghsbh to fortune .pptx
Али махмуд to The teacm of ghsbh to fortune .pptxАли махмуд to The teacm of ghsbh to fortune .pptx
Али махмуд to The teacm of ghsbh to fortune .pptx
palr19411
 
9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj
9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj
9.-Composite-Dr.-B.-Nalini.pptxfdrtyuioklj
aishwaryavdcw
 
egc.pdf tài liệu tiếng Anh cho học sinh THPT
egc.pdf tài liệu tiếng Anh cho học sinh THPTegc.pdf tài liệu tiếng Anh cho học sinh THPT
egc.pdf tài liệu tiếng Anh cho học sinh THPT
huyenmy200809
 
Artificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptxArtificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1)-1.pptx
AbhijitPal87
 
Artificial-Intelligence-in-Autonomous-Vehicles (1).pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1).pptxArtificial-Intelligence-in-Autonomous-Vehicles (1).pptx
Artificial-Intelligence-in-Autonomous-Vehicles (1).pptx
AbhijitPal87
 
Understanding Tree Data Structure and Its Applications
Understanding Tree Data Structure and Its ApplicationsUnderstanding Tree Data Structure and Its Applications
Understanding Tree Data Structure and Its Applications
M Munim
 
llm lecture 3 stanford blah blah blah blah
llm lecture 3 stanford blah blah blah blahllm lecture 3 stanford blah blah blah blah
llm lecture 3 stanford blah blah blah blah
saud140081
 
lecture 33333222234555555555555555556.pptx
lecture 33333222234555555555555555556.pptxlecture 33333222234555555555555555556.pptx
lecture 33333222234555555555555555556.pptx
obsinaafilmakuush
 
Human body make Structure analysis the part of the human
Human body make Structure analysis the part of the humanHuman body make Structure analysis the part of the human
Human body make Structure analysis the part of the human
ankit392215
 
Comprehensive Roadmap of AI, ML, DS, DA & DSA.pdf
Comprehensive Roadmap of AI, ML, DS, DA & DSA.pdfComprehensive Roadmap of AI, ML, DS, DA & DSA.pdf
Comprehensive Roadmap of AI, ML, DS, DA & DSA.pdf
epsilonice
 
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docxHow Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
How Data Annotation Services Drive Innovation in Autonomous Vehicles.docx
sofiawilliams5966
 
BADS-MBA-Unit 1 that what data science and Interpretation
BADS-MBA-Unit 1 that what data science and InterpretationBADS-MBA-Unit 1 that what data science and Interpretation
BADS-MBA-Unit 1 that what data science and Interpretation
srishtisingh1813
 
Data Analytics and visualization-PowerBi
Data Analytics and visualization-PowerBiData Analytics and visualization-PowerBi
Data Analytics and visualization-PowerBi
Krishnapriya975316
 
Ad

Introduction to numpy Session 1

  • 1. Slide 1 Objective of the class • What is numpy? • numpy performance test • Introduction to numpy arrays • Introduction to numpy function • Dealing with Flat files using numpy • Mathematical functions • Statisticals function • Operations with arrays Introduction to Numpy
  • 2. Slide 2 NumPy NumPy is an extension to the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large library of high-level mathematical functions to operate on these arrays To install NumPy run: python setup.py install To perform an in-place build that can be run from the source folder run: python setup.py build_ext --inplace The NumPy build system uses distutils and numpy.distutils. setuptools is only used when building via pip or with python setupegg.py.
  • 3. Slide 3 Official Website: http://www.numpy.org • NumPy is licensed under the BSD license, enabling reuse with few restrictions. • NumPy replaces Numeric and Numarray • Numpy was initially developed by Travis Oliphant • There are 225+ Contributors to the project (github.com) • NumPy 1.0 released October, 2006 • Numpy 1.14.0 is the lastest version of numpy • There are more than 200K downloads/month from PyPI NumPy
  • 5. Slide 5 Getting Started with Numpy >>> # Importing Numpy module >>> import numpy >>> import numpy as np IPython has a ‘pylab’ mode where it imports all of NumPy, Matplotlib, and SciPy into the namespace for you as a convenience. It also enables threading for showing plots
  • 6. Slide 6 Getting Started with Numpy • Arrays are the central feature of NumPy. • Arrays in Python are similar to lists in Python, the only difference being the array elements should be of the same type import numpy as np a = np.array([1,2,3], float) # Accept two arguments list and type print a # Return array([ 1., 2., 3.]) print type(a) # Return <type 'numpy.ndarray'> print a[2] # 3.0 print a.dtype # Print the element type print a.itemsize # print bytes per element print a.shape # print the shape of an array print a.size # print the size of an array
  • 7. Slide 7 a.nbytes # return the total bytes used by an array a.ndim # provide the dimension of an array a[0] = 10.5 # Modify array first index important decimal will come if the array is float type else it will be hold only 10 a.fill(20) # Fill all the values by 20 a[1:3] # Slice the array a[-2:] # Last two elements of an array Getting Started with Numpy
  • 9. Slide 9 import numpy as np a = np.array([[1,2,3], [4,5,6]], int) # Accept two arguments list and type >>> a.shape # Return (2, 3) >>> a.ndim # return 2 >>> a[0][0] # Return 1 >>> a[0,0] # Return 1 >>> a[1,2] # Return 6 >>> a[1:] # Return array([[4, 5, 6]]) >>> a[1,:] # Return array([4, 5, 6]) >>> a[:2] # Return array([[1, 2, 3],[4, 5, 6]]) >>> a[:,2] # Return array([3, 6]) >>> a[:,1] # Return array([2, 5]) >>> a[:,0] # Return array([1, 4]) Multi-Dimensional Arrays
  • 10. Slide 10 import numpy as np a = np.array([[1,2,3], [4,5,6]], int) # Accept two arguments list and type >>> b = a.reshape(3,2) # Return the new shape of array >>> b.shape # Return (3,2) >>> len(a) # Return length of a >>> 2 in a # Check if 2 is available in a >>> b.tolist() # Return [[1, 2], [3, 4], [5, 6]] >>> list(b) # Return [array([1, 2]), array([3, 4]), array([5, 6])] >>> c = b >>> b[0][0] = 10 >>> c # Return array([[10, 2], [ 3, 4], [ 5, 6]]) Reshaping array
  • 11. Slide 11 Slices Are References >>> a = array((0,1,2,3,4)) # create a slice containing only the # last element of a >>> b = a[2:4] >>> b array([2, 3]) >>> b[0] = 10 # changing b changed a! >>> a array([ 0, 1, 10, 3, 4])
  • 12. Slide 12 arange function and slicing >>> a = np.arange(1,80, 2) array([ 1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 67, 69, 71, 73, 75, 77, 79]) >>> a[[1,5,10]] # Return values at index 1,5 and 10 >>> myIndexes = [4,5,6] >>> a[myIndexes] # Return values at indexes 4,5,6.. >>> mask = a % 5 == 0 # Return boolean value at those indexes >>> a[mask] Out[46]: array([ 5, 15, 25, 35, 45, 55, 65, 75])
  • 13. Slide 13 Where function >>> where (a % 5 == 0) # Returns - (array([ 2, 7, 12, 17, 22, 27, 32, 37], dtype=int64),) >>> loc = where(a % 5 == 0) >>> print a[loc] [ 5 15 25 35 45 55 65 75]
  • 14. Slide 14 Flatten Arrays # Create a 2D array >>> a = array([[0,1], [2,3]]) # Flatten out elements to 1D >>> b = a.flatten() >>> b array([0,1,2,3]) # Changing b does not change a >>> b[0] = 10 >>> b array([10,1,2,3]) >>> a array([[0, 1], [2, 3]])
  • 15. Slide 15 >>> a = array([[0,1,2], ... [3,4,5]]) >>> a.shape (2,3) # Transpose swaps the order # of axes. For 2-D this # swaps rows and columns. >>> a.transpose() array([[0, 3], [1, 4],[2, 5]]) # The .T attribute is # equivalent to transpose(). >>> a.T array([[0, 3], [1, 4], [2, 5]]) Transpose Arrays
  • 16. Slide 16 csv = np.loadtxt(r'A:UPDATE PythonModule 11Programsconstituents- financials.csv', skiprows=1, dtype=str, delimiter=",", usecols = (3,4,5)) Arrays from/to ASCII files
  • 17. Slide 17 Other format supported by other similar package