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 (20)

pandas - Python Data Analysis
pandas - Python Data Analysispandas - Python Data Analysis
pandas - Python Data Analysis
 
Pandas
PandasPandas
Pandas
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
 
Introduction to NumPy
Introduction to NumPyIntroduction to NumPy
Introduction to NumPy
 
Sets in python
Sets in pythonSets in python
Sets in python
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
 
Introduction to pandas
Introduction to pandasIntroduction to pandas
Introduction to pandas
 
The matplotlib Library
The matplotlib LibraryThe matplotlib Library
The matplotlib Library
 
Python list
Python listPython list
Python list
 
Matplotlib
MatplotlibMatplotlib
Matplotlib
 
Introduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data AnalyticsIntroduction to Python Pandas for Data Analytics
Introduction to Python Pandas for Data Analytics
 
Python: Modules and Packages
Python: Modules and PackagesPython: Modules and Packages
Python: Modules and Packages
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
NumPy
NumPyNumPy
NumPy
 
Arrays in python
Arrays in pythonArrays in python
Arrays in python
 
Introduction to numpy Session 1
Introduction to numpy Session 1Introduction to numpy Session 1
Introduction to numpy Session 1
 
Datatypes in python
Datatypes in pythonDatatypes in python
Datatypes in python
 
Python Programming Essentials - M24 - math module
Python Programming Essentials - M24 - math modulePython Programming Essentials - M24 - math module
Python Programming Essentials - M24 - math module
 
Python for data analysis
Python for data analysisPython for data analysis
Python for data analysis
 

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

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsKarinaGenton
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting DataJhengPantaleon
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfUmakantAnnand
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon AUnboundStockton
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxOH TEIK BIN
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991RKavithamani
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAssociation for Project Management
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 

Recently uploaded (20)

Science 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its CharacteristicsScience 7 - LAND and SEA BREEZE and its Characteristics
Science 7 - LAND and SEA BREEZE and its Characteristics
 
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data_Math 4-Q4 Week 5.pptx Steps in Collecting Data
_Math 4-Q4 Week 5.pptx Steps in Collecting Data
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Concept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.CompdfConcept of Vouching. B.Com(Hons) /B.Compdf
Concept of Vouching. B.Com(Hons) /B.Compdf
 
Crayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon ACrayon Activity Handout For the Crayon A
Crayon Activity Handout For the Crayon A
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Solving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptxSolving Puzzles Benefits Everyone (English).pptx
Solving Puzzles Benefits Everyone (English).pptx
 
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
Industrial Policy - 1948, 1956, 1973, 1977, 1980, 1991
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Tilak Nagar Delhi reach out to us at 🔝9953056974🔝
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
APM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across SectorsAPM Welcome, APM North West Network Conference, Synergies Across Sectors
APM Welcome, APM North West Network Conference, Synergies Across Sectors
 
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 

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,