SlideShare a Scribd company logo
1 of 1
Download to read offline
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,

More Related Content

What's hot

List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionarynitamhaske
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Pythonprimeteacher32
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib LibraryHaim Michael
 
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
 
pandas - Python Data Analysis
pandas - Python Data Analysispandas - Python Data Analysis
pandas - Python Data AnalysisAndrew Henshaw
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaEdureka!
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python PandasNeeru Mittal
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Edureka!
 
Introduction to pandas
Introduction to pandasIntroduction to pandas
Introduction to pandasPiyush rai
 
Python Seaborn Data Visualization
Python Seaborn Data Visualization Python Seaborn Data Visualization
Python Seaborn Data Visualization Sourabh Sahu
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlibPiyush rai
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Paige Bailey
 
Introduction to NumPy
Introduction to NumPyIntroduction to NumPy
Introduction to NumPyHuy Nguyen
 

What's hot (20)

List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
Python basic
Python basicPython basic
Python basic
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
For Loops and Nesting in Python
For Loops and Nesting in PythonFor Loops and Nesting in Python
For Loops and Nesting in Python
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib Library
 
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
 
pandas - Python Data Analysis
pandas - Python Data Analysispandas - Python Data Analysis
pandas - Python Data Analysis
 
Python libraries
Python librariesPython libraries
Python libraries
 
Variables & Data Types In Python | Edureka
Variables & Data Types In Python | EdurekaVariables & Data Types In Python | Edureka
Variables & Data Types In Python | Edureka
 
Data Analysis with Python Pandas
Data Analysis with Python PandasData Analysis with Python Pandas
Data Analysis with Python Pandas
 
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
 
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
Tkinter Python Tutorial | Python GUI Programming Using Tkinter Tutorial | Pyt...
 
Introduction to pandas
Introduction to pandasIntroduction to pandas
Introduction to pandas
 
Namespaces
NamespacesNamespaces
Namespaces
 
Python list
Python listPython list
Python list
 
Python Seaborn Data Visualization
Python Seaborn Data Visualization Python Seaborn Data Visualization
Python Seaborn Data Visualization
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
 
Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)Python 101: Python for Absolute Beginners (PyTexas 2014)
Python 101: Python for Absolute Beginners (PyTexas 2014)
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Introduction to NumPy
Introduction to NumPyIntroduction to NumPy
Introduction to NumPy
 

Similar to Intoduction to numpy

NumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptxNumPy_Broadcasting Data Science - Python.pptx
NumPy_Broadcasting Data Science - Python.pptxJohnWilliam111370
 
Useful javascript
Useful javascriptUseful javascript
Useful javascriptLei Kang
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In RubyRoss Lawley
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programmingDamian 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.pdfkarthikaparthasarath
 
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
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavVyacheslav Arbuzov
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Namgee Lee
 

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
 
Useful javascript
Useful javascriptUseful javascript
Useful javascript
 
20100528
2010052820100528
20100528
 
20100528
2010052820100528
20100528
 
Thinking Functionally In Ruby
Thinking Functionally In RubyThinking Functionally In Ruby
Thinking Functionally In Ruby
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
Table of Useful R commands.
Table of Useful R commands.Table of Useful R commands.
Table of Useful R commands.
 
Data types
Data typesData types
Data types
 
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
 
R programming language
R programming languageR programming language
R programming language
 
R and data mining
R and data miningR and data mining
R and data mining
 
Python lecture 05
Python lecture 05Python lecture 05
Python lecture 05
 
R for Statistical Computing
R for Statistical ComputingR for Statistical Computing
R for Statistical Computing
 
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!
 
Learn Matlab
Learn MatlabLearn Matlab
Learn Matlab
 
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov VyacheslavSeminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
Seminar PSU 09.04.2013 - 10.04.2013 MiFIT, Arbuzov Vyacheslav
 
Java arrays
Java    arraysJava    arrays
Java arrays
 
Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303Numpy tutorial(final) 20160303
Numpy tutorial(final) 20160303
 
R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
 
arrays
arraysarrays
arrays
 

More from Faraz Ahmed

Number System Conversion
Number System ConversionNumber System Conversion
Number System ConversionFaraz 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 TechnologyFaraz Ahmed
 
Computer Networking Basic
Computer Networking BasicComputer Networking Basic
Computer Networking BasicFaraz Ahmed
 
Professional Ethics
Professional EthicsProfessional Ethics
Professional EthicsFaraz Ahmed
 
Computer random access memory
Computer   random access memoryComputer   random access memory
Computer random access memoryFaraz Ahmed
 
Computer Output Devices
Computer   Output DevicesComputer   Output Devices
Computer Output DevicesFaraz Ahmed
 
Computer Motherboard
Computer   MotherboardComputer   Motherboard
Computer MotherboardFaraz Ahmed
 
Computer input devices
Computer   input devicesComputer   input devices
Computer input devicesFaraz Ahmed
 
computer components
computer componentscomputer components
computer componentsFaraz Ahmed
 
Artificial Intelligence
Artificial Intelligence  Artificial Intelligence
Artificial Intelligence Faraz Ahmed
 

More from Faraz Ahmed (14)

Number System Conversion
Number System ConversionNumber System Conversion
Number System Conversion
 
Data Communication & Computer Network
Data Communication & Computer Network Data Communication & Computer Network
Data Communication & Computer Network
 
Basic CPU (Central Processing Unit)
Basic CPU (Central Processing Unit)Basic CPU (Central Processing Unit)
Basic CPU (Central Processing Unit)
 
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
 
Computer Networking Basic
Computer Networking BasicComputer Networking Basic
Computer Networking Basic
 
Professional Ethics
Professional EthicsProfessional Ethics
Professional Ethics
 
Computer ethics
Computer ethicsComputer ethics
Computer ethics
 
Computer random access memory
Computer   random access memoryComputer   random access memory
Computer random access memory
 
Computer Output Devices
Computer   Output DevicesComputer   Output Devices
Computer Output Devices
 
Computer Motherboard
Computer   MotherboardComputer   Motherboard
Computer Motherboard
 
Computer Memory
Computer MemoryComputer Memory
Computer Memory
 
Computer input devices
Computer   input devicesComputer   input devices
Computer input devices
 
computer components
computer componentscomputer components
computer components
 
Artificial Intelligence
Artificial Intelligence  Artificial Intelligence
Artificial Intelligence
 

Recently uploaded

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...Poonam Aher Patil
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...Nguyen Thanh Tu Collection
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxVishalSingh1417
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfSherif Taha
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfPoh-Sun Goh
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxDr. Ravikiran H M Gowda
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jisc
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfNirmal Dwivedi
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - Englishneillewis46
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxDenish Jangid
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Pooja Bhuva
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17Celine George
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsMebane Rash
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...pradhanghanshyam7136
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSCeline George
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17Celine George
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Pooja Bhuva
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxDr. Sarita Anand
 

Recently uploaded (20)

General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
REMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptxREMIFENTANIL: An Ultra short acting opioid.pptx
REMIFENTANIL: An Ultra short acting opioid.pptx
 
Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)Jamworks pilot and AI at Jisc (20/03/2024)
Jamworks pilot and AI at Jisc (20/03/2024)
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
Beyond_Borders_Understanding_Anime_and_Manga_Fandom_A_Comprehensive_Audience_...
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
Sensory_Experience_and_Emotional_Resonance_in_Gabriel_Okaras_The_Piano_and_Th...
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 

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,