SlideShare a Scribd company logo
1 of 18
Download to read offline
NumPy
What is NumPy?
❖Numerical python Package.
❖It is used for working with the scientific calculations ,Mathematical calculations
and general purpose of array processing.
❖ It provides a high performance multidimensional array object , and tools for
working with these arrays.
❖ Very fast than list.
❖ Elements in Numpy arrays are accessed by using square brackets and can be
initialized by using nested Python Lists.
Things to know in NumPy:-
❖ Difference between List and Numpy
❖Numpy alias name
❖nd array
❖Type of arrays
❖.ndim array
#Import numpy package
import numpy as np
a= np.array([12,78,456,90,10])
print(a)
arange()
import numpy as np
#print the values from 0 to 50 inside an array
a= np.arange(50)
print(a)
Updating array values
We can update the array values with the help of index.
a=[1,2,3,4,5]
a[1]=44
print(a)
reshape()
#To declare rows and columns of an array
import numpy as np
a=np.arange(15).reshape(5,3)
print(a)
#Accessing Array elements
a[1,1]
a[3,2]
Indexing
import numpy as np
# NumPy array with elements from 1 to 9
x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9])
# Index values can be negative.
arr = x[ np. array([1, 3, -3])]
print(arr)
Boolean Indexing
This indexing has some boolean expression as the index. Those elements are
returned which satisfy that Boolean expression. It is used for filtering the desired
element values
import numpy as np
a = np.array([10, 40, 80, 50, 100])
print(a[a>50])
Slicing
import numpy as np
# Arrange elements from 0 to 19
a = np.arange(20)
print("n Array is:n ",a)
# a[ start:stop:step]
print("n a[-8:17:1] = ",a[-8:17:1])
# The : operator means all elements till the end.
print("n a[10:] = ",a[10:])
Basic operations on single array
import numpy as np
a = np.array([1, 2, 5, 3])
# add 1 to every element
print ("Adding 1 to every element:", a+1)
# subtract 3 from each element
print ("Subtracting 3 from each element:", a-3)
# multiply each element by 10
print ("Multiplying each element by 10:", a*10)
# square each element
print ("Squaring each element:", a**2)
Unary operators in numpy
import numpy as np
arr = np.array([[1, 5, 6], [4, 7, 2], [3, 1, 9]])
# maximum element of array
print ("Largest element is:", arr.max())
#print first columns in the array
print ("Row-wise maximum elements:", arr.max(axis = 1))
# minimum element of array
print ("Column-wise minimum elements:", arr.min(axis = 0))
# sum of array elements
print ("Sum of all array elements: “,arr.sum())
Binary operators in NumPy
import numpy as np
a = np.array([[1, 2], [3, 4]])
b = np.array([[4, 3],[2, 1]])
# add arrays
print ("Array sum:n", a + b)
# multiply arrays (element wise multiplication)
print ("Array multiplication:n", a*b)
# matrix multiplication
print ("Matrix multiplication:n", a.dot(b))
NumPy Functions:-
❖ To find the dimensional of the array - (arr_name.ndim)
❖To find the datatype of the array - (arr_name.dtype)
❖To copy the array elements - (arr_name.copy)
❖To viewing the array - (arr_name.view)
❖To change the data type of the array - (arr_name.astype(bool))

More Related Content

Similar to NumPy: A Guide to the Numerical Python Package

Similar to NumPy: A Guide to the Numerical Python Package (20)

NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
 
Numpy in Python.docx
Numpy in Python.docxNumpy in Python.docx
Numpy in Python.docx
 
Class 8b: Numpy & Matplotlib
Class 8b: Numpy & MatplotlibClass 8b: Numpy & Matplotlib
Class 8b: Numpy & Matplotlib
 
arraycreation.pptx
arraycreation.pptxarraycreation.pptx
arraycreation.pptx
 
Numpy
NumpyNumpy
Numpy
 
ARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptxARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptx
 
Python programming : Arrays
Python programming : ArraysPython programming : Arrays
Python programming : Arrays
 
Numpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptxNumpy_defintion_description_usage_examples.pptx
Numpy_defintion_description_usage_examples.pptx
 
List,tuple,dictionary
List,tuple,dictionaryList,tuple,dictionary
List,tuple,dictionary
 
Numpy.pptx
Numpy.pptxNumpy.pptx
Numpy.pptx
 
ECE-PYTHON.docx
ECE-PYTHON.docxECE-PYTHON.docx
ECE-PYTHON.docx
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
 
PPS-UNIT5.ppt
PPS-UNIT5.pptPPS-UNIT5.ppt
PPS-UNIT5.ppt
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
L 5 Numpy final ppt kirti.pptx
L 5 Numpy final ppt kirti.pptxL 5 Numpy final ppt kirti.pptx
L 5 Numpy final ppt kirti.pptx
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Arrays_in_c++.pptx
Arrays_in_c++.pptxArrays_in_c++.pptx
Arrays_in_c++.pptx
 
[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types[ITP - Lecture 15] Arrays & its Types
[ITP - Lecture 15] Arrays & its Types
 
CE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdfCE344L-200365-Lab2.pdf
CE344L-200365-Lab2.pdf
 

More from DineshThallapelly

D.Sai Tharun 20848 BCA 2nd year-converted.pptx
D.Sai Tharun 20848 BCA 2nd year-converted.pptxD.Sai Tharun 20848 BCA 2nd year-converted.pptx
D.Sai Tharun 20848 BCA 2nd year-converted.pptxDineshThallapelly
 
IMG_20230326_134431 (15 files merged).ppt
IMG_20230326_134431 (15 files merged).pptIMG_20230326_134431 (15 files merged).ppt
IMG_20230326_134431 (15 files merged).pptDineshThallapelly
 
IMG_20230325_121848 (13 files merged).ppt
IMG_20230325_121848 (13 files merged).pptIMG_20230325_121848 (13 files merged).ppt
IMG_20230325_121848 (13 files merged).pptDineshThallapelly
 
ACFrOgDHQC5OjIl5Q9jxVubx7Sot2XrlBki_kWu7QeD_CcOBLjkoUqIWzF_pIdWB9F91KupVVJdfR...
ACFrOgDHQC5OjIl5Q9jxVubx7Sot2XrlBki_kWu7QeD_CcOBLjkoUqIWzF_pIdWB9F91KupVVJdfR...ACFrOgDHQC5OjIl5Q9jxVubx7Sot2XrlBki_kWu7QeD_CcOBLjkoUqIWzF_pIdWB9F91KupVVJdfR...
ACFrOgDHQC5OjIl5Q9jxVubx7Sot2XrlBki_kWu7QeD_CcOBLjkoUqIWzF_pIdWB9F91KupVVJdfR...DineshThallapelly
 
newmicrosoftofficepowerpointpresentation-160805121228 (1).pdf
newmicrosoftofficepowerpointpresentation-160805121228 (1).pdfnewmicrosoftofficepowerpointpresentation-160805121228 (1).pdf
newmicrosoftofficepowerpointpresentation-160805121228 (1).pdfDineshThallapelly
 
1601-308-Wright Brothers.pptx
1601-308-Wright Brothers.pptx1601-308-Wright Brothers.pptx
1601-308-Wright Brothers.pptxDineshThallapelly
 

More from DineshThallapelly (6)

D.Sai Tharun 20848 BCA 2nd year-converted.pptx
D.Sai Tharun 20848 BCA 2nd year-converted.pptxD.Sai Tharun 20848 BCA 2nd year-converted.pptx
D.Sai Tharun 20848 BCA 2nd year-converted.pptx
 
IMG_20230326_134431 (15 files merged).ppt
IMG_20230326_134431 (15 files merged).pptIMG_20230326_134431 (15 files merged).ppt
IMG_20230326_134431 (15 files merged).ppt
 
IMG_20230325_121848 (13 files merged).ppt
IMG_20230325_121848 (13 files merged).pptIMG_20230325_121848 (13 files merged).ppt
IMG_20230325_121848 (13 files merged).ppt
 
ACFrOgDHQC5OjIl5Q9jxVubx7Sot2XrlBki_kWu7QeD_CcOBLjkoUqIWzF_pIdWB9F91KupVVJdfR...
ACFrOgDHQC5OjIl5Q9jxVubx7Sot2XrlBki_kWu7QeD_CcOBLjkoUqIWzF_pIdWB9F91KupVVJdfR...ACFrOgDHQC5OjIl5Q9jxVubx7Sot2XrlBki_kWu7QeD_CcOBLjkoUqIWzF_pIdWB9F91KupVVJdfR...
ACFrOgDHQC5OjIl5Q9jxVubx7Sot2XrlBki_kWu7QeD_CcOBLjkoUqIWzF_pIdWB9F91KupVVJdfR...
 
newmicrosoftofficepowerpointpresentation-160805121228 (1).pdf
newmicrosoftofficepowerpointpresentation-160805121228 (1).pdfnewmicrosoftofficepowerpointpresentation-160805121228 (1).pdf
newmicrosoftofficepowerpointpresentation-160805121228 (1).pdf
 
1601-308-Wright Brothers.pptx
1601-308-Wright Brothers.pptx1601-308-Wright Brothers.pptx
1601-308-Wright Brothers.pptx
 

Recently uploaded

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)wesley chun
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 

Recently uploaded (20)

08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 

NumPy: A Guide to the Numerical Python Package

  • 2. What is NumPy? ❖Numerical python Package. ❖It is used for working with the scientific calculations ,Mathematical calculations and general purpose of array processing. ❖ It provides a high performance multidimensional array object , and tools for working with these arrays. ❖ Very fast than list. ❖ Elements in Numpy arrays are accessed by using square brackets and can be initialized by using nested Python Lists.
  • 3. Things to know in NumPy:- ❖ Difference between List and Numpy ❖Numpy alias name ❖nd array ❖Type of arrays ❖.ndim array
  • 4. #Import numpy package import numpy as np a= np.array([12,78,456,90,10]) print(a)
  • 5.
  • 6.
  • 7.
  • 8.
  • 9. arange() import numpy as np #print the values from 0 to 50 inside an array a= np.arange(50) print(a)
  • 10. Updating array values We can update the array values with the help of index. a=[1,2,3,4,5] a[1]=44 print(a)
  • 11. reshape() #To declare rows and columns of an array import numpy as np a=np.arange(15).reshape(5,3) print(a) #Accessing Array elements a[1,1] a[3,2]
  • 12. Indexing import numpy as np # NumPy array with elements from 1 to 9 x = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9]) # Index values can be negative. arr = x[ np. array([1, 3, -3])] print(arr)
  • 13. Boolean Indexing This indexing has some boolean expression as the index. Those elements are returned which satisfy that Boolean expression. It is used for filtering the desired element values import numpy as np a = np.array([10, 40, 80, 50, 100]) print(a[a>50])
  • 14. Slicing import numpy as np # Arrange elements from 0 to 19 a = np.arange(20) print("n Array is:n ",a) # a[ start:stop:step] print("n a[-8:17:1] = ",a[-8:17:1]) # The : operator means all elements till the end. print("n a[10:] = ",a[10:])
  • 15. Basic operations on single array import numpy as np a = np.array([1, 2, 5, 3]) # add 1 to every element print ("Adding 1 to every element:", a+1) # subtract 3 from each element print ("Subtracting 3 from each element:", a-3) # multiply each element by 10 print ("Multiplying each element by 10:", a*10) # square each element print ("Squaring each element:", a**2)
  • 16. Unary operators in numpy import numpy as np arr = np.array([[1, 5, 6], [4, 7, 2], [3, 1, 9]]) # maximum element of array print ("Largest element is:", arr.max()) #print first columns in the array print ("Row-wise maximum elements:", arr.max(axis = 1)) # minimum element of array print ("Column-wise minimum elements:", arr.min(axis = 0)) # sum of array elements print ("Sum of all array elements: “,arr.sum())
  • 17. Binary operators in NumPy import numpy as np a = np.array([[1, 2], [3, 4]]) b = np.array([[4, 3],[2, 1]]) # add arrays print ("Array sum:n", a + b) # multiply arrays (element wise multiplication) print ("Array multiplication:n", a*b) # matrix multiplication print ("Matrix multiplication:n", a.dot(b))
  • 18. NumPy Functions:- ❖ To find the dimensional of the array - (arr_name.ndim) ❖To find the datatype of the array - (arr_name.dtype) ❖To copy the array elements - (arr_name.copy) ❖To viewing the array - (arr_name.view) ❖To change the data type of the array - (arr_name.astype(bool))