SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Downloaden Sie, um offline zu lesen
CLASS- XII
PCT-2 UNIT - 1 CHAPTER -8 Data Visualization : Numpy Array
Prepared By -
Swati Patil
BE, MCA,PGDHRM
Contact -
8618134279 (Queries only through SMS)
https://pythonxiisolutions.blogspot.com prippython12.blogspot.com
Difference between List and Numpy Array
List Array
The list can be homogeneous or heterogeneous The array are homogeneous
Elements of List are not stored contiguously in memory.
2D list may have different number of rows and columns
can
Elements of an array are stored contiguously in
memory. For example, all rows of a 2D array must have
the same number of columns. Or a 3D array must have
the same number of rows and columns on each card.
Python list is by default 1 dimensional. But we can
create an N-Dimensional list. But then too it will be 1 D
list storing another 1D list
Arrays are multi dimensional
Element wise operation is not possible in list.
Example-
# adding 4 to each element of list
ls = ls + 4
Element wise operation is possible in array.
Example-
# adding 4 to each element of Numpy array
arr = arr + 4
range () is used arange() is used
Numerical Python (Num Pie)- It offers function for fast mathematical computation on arrays or
matrices.
PACKAGE:
numpy
import numpy
as np
# Create an array from a list
>>>L=[2,3,4,5]
>>>a=np.array(L)
# use iterator to create array
np.fromiter(iter(range(5)),dtype=int)
array([0, 1, 2, 3, 4])
# Find length of each element of array in bytes
>>>a.itemsize
8
#uninitialized array of specified shape and dtype
x = np.empty([3,2], dtype = int32)
# Find dimension of Numpy array, i.e no of elements
along each axis.
>>>a.shape # returns a Tuple
>>> (4,)
#a reshape function to resize an array.
>>>a.reshape(4,1)
# slicing array
s = slice(1,7,2) OR b = a[1:7:2]
[ 3 5 ] [ 3 5 ]
# ellipsis(...)
a=p.array([[1,2,3],[3,4,5],[4,5,6]])
print(a[...,1],a[1,...],a[...,1:])
[2 4 5] [3 4 5] [[2 3]
[4 5]
[5 6]]
#a new array of specified size, filled with zeros.
x = np.zeros(5)
[ 0. 0. 0. 0. 0.]
#a new array of specified size and type, filled with
ones.
x = np.ones(5)
[ 1. 1. 1. 1. 1.]
# Find data type of an array
>>>a.dtype
dtype('float64')
L=[1,2,3.4,5,6,7]
a=numpy.array(L)
#array([1. , 2. , 3.4, 5.
, 6. , 7. ])
a.shape
(6,)
a .itemsize
8
a.dtype
dtype('float64')
a=numpy.array(L,dty
pe='O')
K=[[2,3,4],[1,5],[8]]
k=numpy.array(K)
k.shape
(3,)
k.itemsize
4
k.dtype
dtype('int32')
k=numpy.array(K,dtype
='O')
S=['w','e','l','c','m','e']
s=numpy.array(S)
s.shape
(6,)
s.itemsize
4
s.dtype
dtype('<U1') # Unicode
s=numpy.array(S,dtype='
O')
l=[ [1,2,3], [4.5,6], ['s', {1:'n'} ], [ (6,7) ] ]
L=numpy.array(l,dtype=object) # dtype must
# L is array([list([1, 2, 3]), list([4.5, 6]), list(['s', {1:
'n'}]),list([(6, 7)])], dtype=object)
L.shape
(4,)
L.itemsize
4
L.dtype
dtype('O') # Object
L=numpy.array(l,dtype='O')
Creating arrays Syntax import numpy as np
Using arange() arr=numpy.arange([start],end,[,step][,dtype]) a=np.arange(5,50,5)
array([ 5, 10, 15, 20, 25, 30, 35, 40, 45])
Using linspace() arr=numpy.linspace(start,end,no. Of values) a=np.linspace(5,50,5)
array([ 5. , 16.25, 27.5 , 38.75, 50. ])
Dtypes of array
Data Type Size Range
np.int8 1 byte -128 to 127
np.int16 2 byte -32768 to 32767
np.int32 4 byte -216
to 216
-1
np.int64 8 byte -232
to 232
-1
np.float_ 8 byte 11exp + 52manti
np.float16 2byte 5exp + 10manti
np.float32 4 byte 8exp+ 23manti
np.float64 8 byte 11exp + 52manti
Problem Statements to work out :.
1.Create a 3 x 4 two-dimensional ndarray from the range of
integers 13..24
2.Write commands to perform following operations on two 4 x 4
ndarrays namely P and Q :
i>Adding 10 to P
ii> multiplication of P & Q
iii>Divide all elements of Q by 7
iv>Calculate log of all elements of P
v>Round all elements of Q to nearest integer
vi>calculate remainders of all elements of P when divided by 7
vi>Calculate square root of all elements of Q

Weitere ähnliche Inhalte

Was ist angesagt?

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
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyKimikazu Kato
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersKimikazu Kato
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPyDevashish Kumar
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaEdureka!
 
Statistical inference for (Python) Data Analysis. An introduction.
Statistical inference for (Python) Data Analysis. An introduction.Statistical inference for (Python) Data Analysis. An introduction.
Statistical inference for (Python) Data Analysis. An introduction.Piotr Milanowski
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlibPiyush rai
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : ArraysGagan Deep
 
Array in c language
Array in c languageArray in c language
Array in c languagehome
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array pptsandhya yadav
 

Was ist angesagt? (20)

Numpy python cheat_sheet
Numpy python cheat_sheetNumpy python cheat_sheet
Numpy python cheat_sheet
 
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
 
Effective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPyEffective Numerical Computation in NumPy and SciPy
Effective Numerical Computation in NumPy and SciPy
 
Python Scipy Numpy
Python Scipy NumpyPython Scipy Numpy
Python Scipy Numpy
 
Introduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning ProgrammersIntroduction to NumPy for Machine Learning Programmers
Introduction to NumPy for Machine Learning Programmers
 
Data Analysis in Python-NumPy
Data Analysis in Python-NumPyData Analysis in Python-NumPy
Data Analysis in Python-NumPy
 
Python NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | EdurekaPython NumPy Tutorial | NumPy Array | Edureka
Python NumPy Tutorial | NumPy Array | Edureka
 
Arrays
ArraysArrays
Arrays
 
Statistical inference for (Python) Data Analysis. An introduction.
Statistical inference for (Python) Data Analysis. An introduction.Statistical inference for (Python) Data Analysis. An introduction.
Statistical inference for (Python) Data Analysis. An introduction.
 
Arrays
ArraysArrays
Arrays
 
Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]Data Structures - Lecture 3 [Arrays]
Data Structures - Lecture 3 [Arrays]
 
2- Dimensional Arrays
2- Dimensional Arrays2- Dimensional Arrays
2- Dimensional Arrays
 
Introduction to matplotlib
Introduction to matplotlibIntroduction to matplotlib
Introduction to matplotlib
 
C++ lecture 04
C++ lecture 04C++ lecture 04
C++ lecture 04
 
Arrays
ArraysArrays
Arrays
 
Arrays
ArraysArrays
Arrays
 
C Programming : Arrays
C Programming : ArraysC Programming : Arrays
C Programming : Arrays
 
Python list
Python listPython list
Python list
 
Array in c language
Array in c languageArray in c language
Array in c language
 
Introduction to Array ppt
Introduction to Array pptIntroduction to Array ppt
Introduction to Array ppt
 

Ähnlich wie Numpy

Ähnlich wie Numpy (20)

numpy.pdf
numpy.pdfnumpy.pdf
numpy.pdf
 
Arrays Introduction.pptx
Arrays Introduction.pptxArrays Introduction.pptx
Arrays Introduction.pptx
 
Python revision tour II
Python revision tour IIPython revision tour II
Python revision tour II
 
11 Introduction to lists.pptx
11 Introduction to lists.pptx11 Introduction to lists.pptx
11 Introduction to lists.pptx
 
unit 2.pptx
unit 2.pptxunit 2.pptx
unit 2.pptx
 
Homework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdfHomework Assignment – Array Technical DocumentWrite a technical .pdf
Homework Assignment – Array Technical DocumentWrite a technical .pdf
 
arraycreation.pptx
arraycreation.pptxarraycreation.pptx
arraycreation.pptx
 
Week 11.pptx
Week 11.pptxWeek 11.pptx
Week 11.pptx
 
Data Manipulation with Numpy and Pandas in PythonStarting with N
Data Manipulation with Numpy and Pandas in PythonStarting with NData Manipulation with Numpy and Pandas in PythonStarting with N
Data Manipulation with Numpy and Pandas in PythonStarting with N
 
Lecture 15 - Array
Lecture 15 - ArrayLecture 15 - Array
Lecture 15 - Array
 
GE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_NotesGE3151_PSPP_UNIT_4_Notes
GE3151_PSPP_UNIT_4_Notes
 
Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm Arrays in Data Structure and Algorithm
Arrays in Data Structure and Algorithm
 
cluod.pdf
cluod.pdfcluod.pdf
cluod.pdf
 
Chap09
Chap09Chap09
Chap09
 
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada ReddyDatastructures and algorithms prepared by M.V.Brehmanada Reddy
Datastructures and algorithms prepared by M.V.Brehmanada Reddy
 
Python-List.pptx
Python-List.pptxPython-List.pptx
Python-List.pptx
 
NUMPY-2.pptx
NUMPY-2.pptxNUMPY-2.pptx
NUMPY-2.pptx
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
NumPy.pptx
NumPy.pptxNumPy.pptx
NumPy.pptx
 
Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional Arrays 1D and 2D , and multi dimensional
Arrays 1D and 2D , and multi dimensional
 

Mehr von ToniyaP1

Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear listsToniyaP1
 
Python library
Python libraryPython library
Python libraryToniyaP1
 
Python algorithm efficency
Python algorithm efficencyPython algorithm efficency
Python algorithm efficencyToniyaP1
 
Python data file handling
Python data file handlingPython data file handling
Python data file handlingToniyaP1
 
Python functions
Python functionsPython functions
Python functionsToniyaP1
 
Python recursion
Python recursionPython recursion
Python recursionToniyaP1
 

Mehr von ToniyaP1 (6)

Data structures: linear lists
Data structures: linear listsData structures: linear lists
Data structures: linear lists
 
Python library
Python libraryPython library
Python library
 
Python algorithm efficency
Python algorithm efficencyPython algorithm efficency
Python algorithm efficency
 
Python data file handling
Python data file handlingPython data file handling
Python data file handling
 
Python functions
Python functionsPython functions
Python functions
 
Python recursion
Python recursionPython recursion
Python recursion
 

Kürzlich hochgeladen

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxJisc
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...Amil baba
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024Elizabeth Walsh
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and ModificationsMJDuyan
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxPooja Bhuva
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentationcamerronhm
 
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
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxUmeshTimilsina1
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxPooja Bhuva
 
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
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsKarakKing
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxAreebaZafar22
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxPooja Bhuva
 
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
 
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
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfDr Vijay Vishwakarma
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxheathfieldcps1
 
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
 
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
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxannathomasp01
 

Kürzlich hochgeladen (20)

Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
NO1 Top Black Magic Specialist In Lahore Black magic In Pakistan Kala Ilam Ex...
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
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
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.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)
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Interdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptxInterdisciplinary_Insights_Data_Collection_Methods.pptx
Interdisciplinary_Insights_Data_Collection_Methods.pptx
 
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Ữ Â...
 
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
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
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...
 
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...
 
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptxCOMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
COMMUNICATING NEGATIVE NEWS - APPROACHES .pptx
 

Numpy

  • 1. CLASS- XII PCT-2 UNIT - 1 CHAPTER -8 Data Visualization : Numpy Array Prepared By - Swati Patil BE, MCA,PGDHRM Contact - 8618134279 (Queries only through SMS) https://pythonxiisolutions.blogspot.com prippython12.blogspot.com
  • 2. Difference between List and Numpy Array List Array The list can be homogeneous or heterogeneous The array are homogeneous Elements of List are not stored contiguously in memory. 2D list may have different number of rows and columns can Elements of an array are stored contiguously in memory. For example, all rows of a 2D array must have the same number of columns. Or a 3D array must have the same number of rows and columns on each card. Python list is by default 1 dimensional. But we can create an N-Dimensional list. But then too it will be 1 D list storing another 1D list Arrays are multi dimensional Element wise operation is not possible in list. Example- # adding 4 to each element of list ls = ls + 4 Element wise operation is possible in array. Example- # adding 4 to each element of Numpy array arr = arr + 4 range () is used arange() is used
  • 3. Numerical Python (Num Pie)- It offers function for fast mathematical computation on arrays or matrices. PACKAGE: numpy import numpy as np # Create an array from a list >>>L=[2,3,4,5] >>>a=np.array(L) # use iterator to create array np.fromiter(iter(range(5)),dtype=int) array([0, 1, 2, 3, 4]) # Find length of each element of array in bytes >>>a.itemsize 8 #uninitialized array of specified shape and dtype x = np.empty([3,2], dtype = int32) # Find dimension of Numpy array, i.e no of elements along each axis. >>>a.shape # returns a Tuple >>> (4,) #a reshape function to resize an array. >>>a.reshape(4,1) # slicing array s = slice(1,7,2) OR b = a[1:7:2] [ 3 5 ] [ 3 5 ] # ellipsis(...) a=p.array([[1,2,3],[3,4,5],[4,5,6]]) print(a[...,1],a[1,...],a[...,1:]) [2 4 5] [3 4 5] [[2 3] [4 5] [5 6]] #a new array of specified size, filled with zeros. x = np.zeros(5) [ 0. 0. 0. 0. 0.] #a new array of specified size and type, filled with ones. x = np.ones(5) [ 1. 1. 1. 1. 1.] # Find data type of an array >>>a.dtype dtype('float64')
  • 4. L=[1,2,3.4,5,6,7] a=numpy.array(L) #array([1. , 2. , 3.4, 5. , 6. , 7. ]) a.shape (6,) a .itemsize 8 a.dtype dtype('float64') a=numpy.array(L,dty pe='O') K=[[2,3,4],[1,5],[8]] k=numpy.array(K) k.shape (3,) k.itemsize 4 k.dtype dtype('int32') k=numpy.array(K,dtype ='O') S=['w','e','l','c','m','e'] s=numpy.array(S) s.shape (6,) s.itemsize 4 s.dtype dtype('<U1') # Unicode s=numpy.array(S,dtype=' O') l=[ [1,2,3], [4.5,6], ['s', {1:'n'} ], [ (6,7) ] ] L=numpy.array(l,dtype=object) # dtype must # L is array([list([1, 2, 3]), list([4.5, 6]), list(['s', {1: 'n'}]),list([(6, 7)])], dtype=object) L.shape (4,) L.itemsize 4 L.dtype dtype('O') # Object L=numpy.array(l,dtype='O') Creating arrays Syntax import numpy as np Using arange() arr=numpy.arange([start],end,[,step][,dtype]) a=np.arange(5,50,5) array([ 5, 10, 15, 20, 25, 30, 35, 40, 45]) Using linspace() arr=numpy.linspace(start,end,no. Of values) a=np.linspace(5,50,5) array([ 5. , 16.25, 27.5 , 38.75, 50. ])
  • 5. Dtypes of array Data Type Size Range np.int8 1 byte -128 to 127 np.int16 2 byte -32768 to 32767 np.int32 4 byte -216 to 216 -1 np.int64 8 byte -232 to 232 -1 np.float_ 8 byte 11exp + 52manti np.float16 2byte 5exp + 10manti np.float32 4 byte 8exp+ 23manti np.float64 8 byte 11exp + 52manti Problem Statements to work out :. 1.Create a 3 x 4 two-dimensional ndarray from the range of integers 13..24 2.Write commands to perform following operations on two 4 x 4 ndarrays namely P and Q : i>Adding 10 to P ii> multiplication of P & Q iii>Divide all elements of Q by 7 iv>Calculate log of all elements of P v>Round all elements of Q to nearest integer vi>calculate remainders of all elements of P when divided by 7 vi>Calculate square root of all elements of Q