SlideShare a Scribd company logo
Numpy Tutorial
NumPy is a general-purpose array-processing package. It provides a high-performance
multidimensional array object, and tools for working with these arrays. It is the fundamental
package for scientific computing with Python.
What is an array
An array is a data structure that stores values of same data type. In Python, this is the main
difference between arrays and lists. While python lists can contain values corresponding to
different data types, arrays in python can only contain values corresponding to same data type.
Why we use array
Array operations are very very fast.
Most of the time we use two dimentional array in Exploratory Data Analysis.
In [6]: import numpy as np
In [ ]: my_list = [1,2,3,4,5]
arr = np.array(my_list)
In [ ]: print(arr)
In [36]: my_list1 = (1,2,3,4,5)
my_list2 = (6,7,8,9,10)
my_list3 = (2,4,6,8,10)
arr = np.array([my_list1,my_list2,my_list3])
In [37]: arr
In [38]: arr.shape
In [41]: arr.reshape(5,3)
In [9]: arr
In [7]: arr = np.array(range(11))
In [ ]:
In [ ]: arr = np.arrary
Indexing
In [49]: arr[1:3,2:4]
In [50]: arr[1:2,1:-1]
In [26]: arr = np.array(range(11))
In [27]: arr
In [12]: arr_1 = arr
arr_1
In [11]: # Defining the problem
arr_1[5:] = 100 # making change in arr_1
print("arr_1 =",arr_1) # arr_1 change
print("arr_1 =",arr) # arr also change
In [13]: # Defining solution with copy() method.
arr = np.array(range(11))
print("arr =",arr)
arr_1 = arr.copy() # Making a copy of arr and assigning to arr_1
arr_1[5:] = 100 # Making change in arr_1 but this time not effect on
arr
print("arr_1 =",arr_1)
print("arr =",arr)
Some Important Conditions used in Exploratory Data
Analysis
In [16]: val = 5
arr < 5
In [24]: val = 2
print(arr, 'arr')
print(arr + val, 'arr + val')
print(arr - val, 'arr - val')
print(arr * val, 'arr * val')
print(arr / val, 'arr / val')
print(arr % val, 'arr % val')
print(arr > val, 'arr > val')
print(arr < val, 'arr < val')
# print(arr)
In [35]: print(f"{arr[arr%2 == 0]}tt= arr%2 == 0")
print(f"{arr[arr > 2]}t= arr > 2")
print(f"{arr[arr != 5]}t= arr != 5")
print(f"{arr[arr == 5]}tttt= arr == 5")
print(arr)
Applying arithmatic operation between two arrays.
In [39]: array_1 = np.arange(10).reshape(2,5)
print(array_1)
array_2 = np.arange(10).reshape(2,5)
print(array_1)
In [40]: array_1 * array_2
In [ ]:
In [56]: arange = np.arange(2,21,2)
In [33]: arr
In [31]: arr1 = arr[:]
print(arr1)
In [32]: arr1[3:] = 50
print(arr1)
In [29]: #copy function and broadcasting.
arr[3:]=100
In [1]: arr
Some inbuilt method
arange()
it is like range() function ### linspace()
it generate special kind series in which the differnce between all elements is equal. ### copy()
is used to copy an arry while assigning one arry form one variable to another, this provide
solution of ie:.reference type vs value type, by creating a new memory for copied variable.
In [60]: n p.linspace(1,10,50)
Out[37]: array([[ 1, 2, 3, 4, 5],
[ 6, 7, 8, 9, 10],
[ 2, 4, 6, 8, 10]])
Out[38]: (3, 5)
Out[41]: array([[ 1, 2, 3],
[ 4, 5, 6],
[ 7, 8, 9],
[10, 2, 4],
[ 6, 8, 10]])
Out[9]: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Out[49]: array([[8, 9],
[6, 8]])
Out[50]: array([[7, 8, 9]])
Out[27]: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10])
Out[12]: array([ 0, 1, 2, 3, 4, 100, 100, 100, 100, 100, 100])
arr_1 = [ 0 1 2 3 4 100 100 100 100 100 100]
arr_1 = [ 0 1 2 3 4 100 100 100 100 100 100]
arr = [ 0 1 2 3 4 5 6 7 8 9 10]
arr_1 = [ 0 1 2 3 4 100 100 100 100 100 100]
arr = [ 0 1 2 3 4 5 6 7 8 9 10]
Out[16]: array([ True, True, True, True, True, False, False, False, False,
False, False])
[ 0 1 2 3 4 5 6 7 8 9 10] arr
[ 2 3 4 5 6 7 8 9 10 11 12] arr + val
[-2 -1 0 1 2 3 4 5 6 7 8] arr - val
[ 0 2 4 6 8 10 12 14 16 18 20] arr * val
[0. 0.5 1. 1.5 2. 2.5 3. 3.5 4. 4.5 5. ] arr / val
[0 1 0 1 0 1 0 1 0 1 0] arr % val
[False False False True True True True True True True True] arr
> val
[ True True False False False False False False False False False] arr
< val
[ 0 2 4 6 8 10] = arr%2 == 0
[ 3 4 5 6 7 8 9 10] = arr > 2
[ 0 1 2 3 4 6 7 8 9 10] = arr != 5
[5] = arr == 5
[ 0 1 2 3 4 5 6 7 8 9 10]
[[0 1 2 3 4]
[5 6 7 8 9]]
[[0 1 2 3 4]
[5 6 7 8 9]]
Out[40]: array([[ 0, 1, 4, 9, 16],
[25, 36, 49, 64, 81]])
Out[33]: array([ 0, 1, 2, 50, 50, 50, 50, 50, 50, 50, 50])
[ 0 1 2 100 100 100 100 100 100 100 100]
[ 0 1 2 50 50 50 50 50 50 50 50]
------------------------------------------------------------------------
---
NameError Traceback (most recent call la
st)
<ipython-input-1-24a6d41c5b66> in <module>
----> 1 arr
NameError: name 'arr' is not defined
Out[60]: array([ 1. , 1.18367347, 1.36734694, 1.55102041, 1.73469388,
1.91836735, 2.10204082, 2.28571429, 2.46938776, 2.65306122,
2.83673469, 3.02040816, 3.20408163, 3.3877551 , 3.57142857,
3.75510204, 3.93877551, 4.12244898, 4.30612245, 4.48979592,
4.67346939, 4.85714286, 5.04081633, 5.2244898 , 5.40816327,
5.59183673, 5.7755102 , 5.95918367, 6.14285714, 6.32653061,
6.51020408, 6.69387755, 6.87755102, 7.06122449, 7.24489796,
7.42857143, 7.6122449 , 7.79591837, 7.97959184, 8.16326531,
Ad

More Related Content

What's hot (20)

Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
Merge sort
Merge sortMerge sort
Merge sort
Vidushi Pathak
 
Numpy tutorial
Numpy tutorialNumpy tutorial
Numpy tutorial
HarikaReddy115
 
Introduction to NumPy
Introduction to NumPyIntroduction to NumPy
Introduction to NumPy
Huy Nguyen
 
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuanScientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
Wei-Yuan Chang
 
pandas - Python Data Analysis
pandas - Python Data Analysispandas - Python Data Analysis
pandas - Python Data Analysis
Andrew Henshaw
 
MatplotLib.pptx
MatplotLib.pptxMatplotLib.pptx
MatplotLib.pptx
Paras Intotech
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
Sukrit Gupta
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
Piyush rai
 
Numpy
NumpyNumpy
Numpy
Jyoti shukla
 
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
Andrew Ferlitsch
 
Python- Regular expression
Python- Regular expressionPython- Regular expression
Python- Regular expression
Megha V
 
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Edureka!
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Umesh Kumar
 
Sorting in python
Sorting in python Sorting in python
Sorting in python
Simplilearn
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
Emertxe Information Technologies Pvt Ltd
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
5.1 greedy
5.1 greedy5.1 greedy
5.1 greedy
Krish_ver2
 
Python Pandas
Python PandasPython Pandas
Python Pandas
Sunil OS
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 
Algorithm: Quick-Sort
Algorithm: Quick-SortAlgorithm: Quick-Sort
Algorithm: Quick-Sort
Tareq Hasan
 
Introduction to NumPy
Introduction to NumPyIntroduction to NumPy
Introduction to NumPy
Huy Nguyen
 
Scientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuanScientific Computing with Python - NumPy | WeiYuan
Scientific Computing with Python - NumPy | WeiYuan
Wei-Yuan Chang
 
pandas - Python Data Analysis
pandas - Python Data Analysispandas - Python Data Analysis
pandas - Python Data Analysis
Andrew Henshaw
 
The n Queen Problem
The n Queen ProblemThe n Queen Problem
The n Queen Problem
Sukrit Gupta
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
Piyush rai
 
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
Andrew Ferlitsch
 
Python- Regular expression
Python- Regular expressionPython- Regular expression
Python- Regular expression
Megha V
 
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Python Matplotlib Tutorial | Matplotlib Tutorial | Python Tutorial | Python T...
Edureka!
 
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
PPT On Sorting And Searching Concepts In Data Structure | In Programming Lang...
Umesh Kumar
 
Sorting in python
Sorting in python Sorting in python
Sorting in python
Simplilearn
 
Divide and conquer - Quick sort
Divide and conquer - Quick sortDivide and conquer - Quick sort
Divide and conquer - Quick sort
Madhu Bala
 
Python Pandas
Python PandasPython Pandas
Python Pandas
Sunil OS
 
8 queens problem using back tracking
8 queens problem using back tracking8 queens problem using back tracking
8 queens problem using back tracking
Tech_MX
 

Similar to Intoduction to numpy (20)

NumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptxNumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptx
JohnWilliam111370
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
Lei Kang
 
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
 
20100528
2010052820100528
20100528
byron zhao
 
20100528
2010052820100528
20100528
byron zhao
 
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
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
Ross Lawley
 
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-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
 
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
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
Damian T. Gordon
 
Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.
Dr. Volkan OBAN
 
Data types
Data typesData types
Data types
Rajesh Kone
 
BUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdfBUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdf
karthikaparthasarath
 
R programming language
R programming languageR programming language
R programming language
Alberto Minetti
 
R and data mining
R and data miningR and data mining
R and data mining
Chaozhong Yang
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
Tanwir Zaman
 
R for Statistical Computing
R for Statistical ComputingR for Statistical Computing
R for Statistical Computing
Mohammed El Rafie Tarabay
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
Paige Bailey
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
Abd El Kareem Ahmed
 
NumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptxNumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptx
JohnWilliam111370
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
Lei Kang
 
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
 
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
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
Ross Lawley
 
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-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
 
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
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
Damian T. Gordon
 
Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.
Dr. Volkan OBAN
 
BUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdfBUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdf
karthikaparthasarath
 
Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!Python 101++: Let's Get Down to Business!
Python 101++: Let's Get Down to Business!
Paige Bailey
 
Ad

More from Faraz Ahmed (14)

Number System Conversion
Number System ConversionNumber System Conversion
Number System Conversion
Faraz Ahmed
 
Data Communication & Computer Network
Data Communication & Computer Network Data Communication & Computer Network
Data Communication & Computer Network
Faraz Ahmed
 
Basic CPU (Central Processing Unit)
Basic CPU (Central Processing Unit)Basic CPU (Central Processing Unit)
Basic CPU (Central Processing Unit)
Faraz Ahmed
 
History and Introduction to Information and Communication Technology
History and Introduction to Information and Communication TechnologyHistory and Introduction to Information and Communication Technology
History and Introduction to Information and Communication Technology
Faraz Ahmed
 
Computer Networking Basic
Computer Networking BasicComputer Networking Basic
Computer Networking Basic
Faraz Ahmed
 
Professional Ethics
Professional EthicsProfessional Ethics
Professional Ethics
Faraz Ahmed
 
Computer ethics
Computer ethicsComputer ethics
Computer ethics
Faraz Ahmed
 
Computer random access memory
Computer   random access memoryComputer   random access memory
Computer random access memory
Faraz Ahmed
 
Computer Output Devices
Computer   Output DevicesComputer   Output Devices
Computer Output Devices
Faraz Ahmed
 
Computer Motherboard
Computer   MotherboardComputer   Motherboard
Computer Motherboard
Faraz Ahmed
 
Computer Memory
Computer MemoryComputer Memory
Computer Memory
Faraz Ahmed
 
Computer input devices
Computer   input devicesComputer   input devices
Computer input devices
Faraz Ahmed
 
computer components
computer componentscomputer components
computer components
Faraz Ahmed
 
Artificial Intelligence
Artificial Intelligence  Artificial Intelligence
Artificial Intelligence
Faraz Ahmed
 
Number System Conversion
Number System ConversionNumber System Conversion
Number System Conversion
Faraz Ahmed
 
Data Communication & Computer Network
Data Communication & Computer Network Data Communication & Computer Network
Data Communication & Computer Network
Faraz Ahmed
 
Basic CPU (Central Processing Unit)
Basic CPU (Central Processing Unit)Basic CPU (Central Processing Unit)
Basic CPU (Central Processing Unit)
Faraz Ahmed
 
History and Introduction to Information and Communication Technology
History and Introduction to Information and Communication TechnologyHistory and Introduction to Information and Communication Technology
History and Introduction to Information and Communication Technology
Faraz Ahmed
 
Computer Networking Basic
Computer Networking BasicComputer Networking Basic
Computer Networking Basic
Faraz Ahmed
 
Professional Ethics
Professional EthicsProfessional Ethics
Professional Ethics
Faraz Ahmed
 
Computer random access memory
Computer   random access memoryComputer   random access memory
Computer random access memory
Faraz Ahmed
 
Computer Output Devices
Computer   Output DevicesComputer   Output Devices
Computer Output Devices
Faraz Ahmed
 
Computer Motherboard
Computer   MotherboardComputer   Motherboard
Computer Motherboard
Faraz Ahmed
 
Computer input devices
Computer   input devicesComputer   input devices
Computer input devices
Faraz Ahmed
 
computer components
computer componentscomputer components
computer components
Faraz Ahmed
 
Artificial Intelligence
Artificial Intelligence  Artificial Intelligence
Artificial Intelligence
Faraz Ahmed
 
Ad

Recently uploaded (20)

To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Unit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdfUnit 6_Introduction_Phishing_Password Cracking.pdf
Unit 6_Introduction_Phishing_Password Cracking.pdf
KanchanPatil34
 
Odoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo SlidesOdoo Inventory Rules and Routes v17 - Odoo Slides
Odoo Inventory Rules and Routes v17 - Odoo Slides
Celine George
 
How to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odooHow to Set warnings for invoicing specific customers in odoo
How to Set warnings for invoicing specific customers in odoo
Celine George
 
One Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learningOne Hot encoding a revolution in Machine learning
One Hot encoding a revolution in Machine learning
momer9505
 
The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...The ever evoilving world of science /7th class science curiosity /samyans aca...
The ever evoilving world of science /7th class science curiosity /samyans aca...
Sandeep Swamy
 
GDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptxGDGLSPGCOER - Git and GitHub Workshop.pptx
GDGLSPGCOER - Git and GitHub Workshop.pptx
azeenhodekar
 
LDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini UpdatesLDMMIA Reiki Master Spring 2025 Mini Updates
LDMMIA Reiki Master Spring 2025 Mini Updates
LDM Mia eStudios
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
apa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdfapa-style-referencing-visual-guide-2025.pdf
apa-style-referencing-visual-guide-2025.pdf
Ishika Ghosh
 
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
How to track Cost and Revenue using Analytic Accounts in odoo Accounting, App...
Celine George
 
How to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 WebsiteHow to Subscribe Newsletter From Odoo 18 Website
How to Subscribe Newsletter From Odoo 18 Website
Celine George
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Quality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdfQuality Contril Analysis of Containers.pdf
Quality Contril Analysis of Containers.pdf
Dr. Bindiya Chauhan
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 

Intoduction to numpy

  • 1. Numpy Tutorial NumPy is a general-purpose array-processing package. It provides a high-performance multidimensional array object, and tools for working with these arrays. It is the fundamental package for scientific computing with Python. What is an array An array is a data structure that stores values of same data type. In Python, this is the main difference between arrays and lists. While python lists can contain values corresponding to different data types, arrays in python can only contain values corresponding to same data type. Why we use array Array operations are very very fast. Most of the time we use two dimentional array in Exploratory Data Analysis. In [6]: import numpy as np In [ ]: my_list = [1,2,3,4,5] arr = np.array(my_list) In [ ]: print(arr) In [36]: my_list1 = (1,2,3,4,5) my_list2 = (6,7,8,9,10) my_list3 = (2,4,6,8,10) arr = np.array([my_list1,my_list2,my_list3]) In [37]: arr In [38]: arr.shape In [41]: arr.reshape(5,3) In [9]: arr In [7]: arr = np.array(range(11)) In [ ]: In [ ]: arr = np.arrary Indexing In [49]: arr[1:3,2:4] In [50]: arr[1:2,1:-1] In [26]: arr = np.array(range(11)) In [27]: arr In [12]: arr_1 = arr arr_1 In [11]: # Defining the problem arr_1[5:] = 100 # making change in arr_1 print("arr_1 =",arr_1) # arr_1 change print("arr_1 =",arr) # arr also change In [13]: # Defining solution with copy() method. arr = np.array(range(11)) print("arr =",arr) arr_1 = arr.copy() # Making a copy of arr and assigning to arr_1 arr_1[5:] = 100 # Making change in arr_1 but this time not effect on arr print("arr_1 =",arr_1) print("arr =",arr) Some Important Conditions used in Exploratory Data Analysis In [16]: val = 5 arr < 5 In [24]: val = 2 print(arr, 'arr') print(arr + val, 'arr + val') print(arr - val, 'arr - val') print(arr * val, 'arr * val') print(arr / val, 'arr / val') print(arr % val, 'arr % val') print(arr > val, 'arr > val') print(arr < val, 'arr < val') # print(arr) In [35]: print(f"{arr[arr%2 == 0]}tt= arr%2 == 0") print(f"{arr[arr > 2]}t= arr > 2") print(f"{arr[arr != 5]}t= arr != 5") print(f"{arr[arr == 5]}tttt= arr == 5") print(arr) Applying arithmatic operation between two arrays. In [39]: array_1 = np.arange(10).reshape(2,5) print(array_1) array_2 = np.arange(10).reshape(2,5) print(array_1) In [40]: array_1 * array_2 In [ ]: In [56]: arange = np.arange(2,21,2) In [33]: arr In [31]: arr1 = arr[:] print(arr1) In [32]: arr1[3:] = 50 print(arr1) In [29]: #copy function and broadcasting. arr[3:]=100 In [1]: arr Some inbuilt method arange() it is like range() function ### linspace() it generate special kind series in which the differnce between all elements is equal. ### copy() is used to copy an arry while assigning one arry form one variable to another, this provide solution of ie:.reference type vs value type, by creating a new memory for copied variable. In [60]: n p.linspace(1,10,50) Out[37]: array([[ 1, 2, 3, 4, 5], [ 6, 7, 8, 9, 10], [ 2, 4, 6, 8, 10]]) Out[38]: (3, 5) Out[41]: array([[ 1, 2, 3], [ 4, 5, 6], [ 7, 8, 9], [10, 2, 4], [ 6, 8, 10]]) Out[9]: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) Out[49]: array([[8, 9], [6, 8]]) Out[50]: array([[7, 8, 9]]) Out[27]: array([ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) Out[12]: array([ 0, 1, 2, 3, 4, 100, 100, 100, 100, 100, 100]) arr_1 = [ 0 1 2 3 4 100 100 100 100 100 100] arr_1 = [ 0 1 2 3 4 100 100 100 100 100 100] arr = [ 0 1 2 3 4 5 6 7 8 9 10] arr_1 = [ 0 1 2 3 4 100 100 100 100 100 100] arr = [ 0 1 2 3 4 5 6 7 8 9 10] Out[16]: array([ True, True, True, True, True, False, False, False, False, False, False]) [ 0 1 2 3 4 5 6 7 8 9 10] arr [ 2 3 4 5 6 7 8 9 10 11 12] arr + val [-2 -1 0 1 2 3 4 5 6 7 8] arr - val [ 0 2 4 6 8 10 12 14 16 18 20] arr * val [0. 0.5 1. 1.5 2. 2.5 3. 3.5 4. 4.5 5. ] arr / val [0 1 0 1 0 1 0 1 0 1 0] arr % val [False False False True True True True True True True True] arr > val [ True True False False False False False False False False False] arr < val [ 0 2 4 6 8 10] = arr%2 == 0 [ 3 4 5 6 7 8 9 10] = arr > 2 [ 0 1 2 3 4 6 7 8 9 10] = arr != 5 [5] = arr == 5 [ 0 1 2 3 4 5 6 7 8 9 10] [[0 1 2 3 4] [5 6 7 8 9]] [[0 1 2 3 4] [5 6 7 8 9]] Out[40]: array([[ 0, 1, 4, 9, 16], [25, 36, 49, 64, 81]]) Out[33]: array([ 0, 1, 2, 50, 50, 50, 50, 50, 50, 50, 50]) [ 0 1 2 100 100 100 100 100 100 100 100] [ 0 1 2 50 50 50 50 50 50 50 50] ------------------------------------------------------------------------ --- NameError Traceback (most recent call la st) <ipython-input-1-24a6d41c5b66> in <module> ----> 1 arr NameError: name 'arr' is not defined Out[60]: array([ 1. , 1.18367347, 1.36734694, 1.55102041, 1.73469388, 1.91836735, 2.10204082, 2.28571429, 2.46938776, 2.65306122, 2.83673469, 3.02040816, 3.20408163, 3.3877551 , 3.57142857, 3.75510204, 3.93877551, 4.12244898, 4.30612245, 4.48979592, 4.67346939, 4.85714286, 5.04081633, 5.2244898 , 5.40816327, 5.59183673, 5.7755102 , 5.95918367, 6.14285714, 6.32653061, 6.51020408, 6.69387755, 6.87755102, 7.06122449, 7.24489796, 7.42857143, 7.6122449 , 7.79591837, 7.97959184, 8.16326531,