SlideShare a Scribd company logo
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

More Related Content

PPTX
NumPy
AbhijeetAnand88
 
PPTX
Numpy
Jyoti shukla
 
PPTX
Introduction to numpy Session 1
Jatin Miglani
 
PPTX
Introduction to numpy
Gaurav Aggarwal
 
PDF
Introduction to NumPy (PyData SV 2013)
PyData
 
KEY
NumPy/SciPy Statistics
Enthought, Inc.
 
PDF
NumPy Refresher
Lukasz Dobrzanski
 
Introduction to numpy Session 1
Jatin Miglani
 
Introduction to numpy
Gaurav Aggarwal
 
Introduction to NumPy (PyData SV 2013)
PyData
 
NumPy/SciPy Statistics
Enthought, Inc.
 
NumPy Refresher
Lukasz Dobrzanski
 

What's hot (20)

PDF
Numpy python cheat_sheet
Nishant Upadhyay
 
PPTX
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Andrew Ferlitsch
 
PDF
Effective Numerical Computation in NumPy and SciPy
Kimikazu Kato
 
PPTX
Python Scipy Numpy
Girish Khanzode
 
PDF
Introduction to NumPy for Machine Learning Programmers
Kimikazu Kato
 
PPTX
Data Analysis in Python-NumPy
Devashish Kumar
 
PDF
Python NumPy Tutorial | NumPy Array | Edureka
Edureka!
 
PPTX
Arrays
Trupti Agrawal
 
PDF
Statistical inference for (Python) Data Analysis. An introduction.
Piotr Milanowski
 
PDF
Arrays
Shakila Mahjabin
 
PPTX
Data Structures - Lecture 3 [Arrays]
Muhammad Hammad Waseem
 
PPTX
2- Dimensional Arrays
Education Front
 
PPTX
Introduction to matplotlib
Piyush rai
 
PPTX
C++ lecture 04
HNDE Labuduwa Galle
 
PPT
Arrays
Rahul Mahamuni
 
PPT
Arrays
Aman Agarwal
 
PPSX
C Programming : Arrays
Gagan Deep
 
PDF
Python list
Prof. Dr. K. Adisesha
 
PPTX
Array in c language
home
 
PPTX
Introduction to Array ppt
sandhya yadav
 
Numpy python cheat_sheet
Nishant Upadhyay
 
Python - Numpy/Pandas/Matplot Machine Learning Libraries
Andrew Ferlitsch
 
Effective Numerical Computation in NumPy and SciPy
Kimikazu Kato
 
Python Scipy Numpy
Girish Khanzode
 
Introduction to NumPy for Machine Learning Programmers
Kimikazu Kato
 
Data Analysis in Python-NumPy
Devashish Kumar
 
Python NumPy Tutorial | NumPy Array | Edureka
Edureka!
 
Statistical inference for (Python) Data Analysis. An introduction.
Piotr Milanowski
 
Data Structures - Lecture 3 [Arrays]
Muhammad Hammad Waseem
 
2- Dimensional Arrays
Education Front
 
Introduction to matplotlib
Piyush rai
 
C++ lecture 04
HNDE Labuduwa Galle
 
Arrays
Aman Agarwal
 
C Programming : Arrays
Gagan Deep
 
Array in c language
home
 
Introduction to Array ppt
sandhya yadav
 
Ad

Similar to Numpy (20)

PDF
numpy.pdf
DrSudheerHanumanthak
 
PDF
Numpy - Array.pdf
AnkitaArjunDevkate
 
PPTX
numpy code and examples with attributes.pptx
swathis752031
 
PPTX
numpydocococ34554367827839271966666.pptx
sankarhariharan2007
 
PPTX
Week 11.pptx
CruiseCH
 
PPTX
1.NumPy is a Python library used for wor
DrAtulZende
 
PPTX
NumPy.pptx
DrJasmineBeulahG
 
PPTX
arraycreation.pptx
sathya930629
 
DOCX
Numpy in Python.docx
manohar25689
 
PDF
Scientific Computing with Python - NumPy | WeiYuan
Wei-Yuan Chang
 
PPTX
Numpy_Pandas_for beginners_________.pptx
Abhi Marvel
 
PPT
Python crash course libraries numpy-1, panda.ppt
janaki raman
 
PPT
CAP776Numpy (2).ppt
ChhaviCoachingCenter
 
PPT
CAP776Numpy.ppt
kdr52121
 
PPTX
Usage of Python NumPy, 1Dim, 2Dim Arrays
NarendraDev11
 
PPTX
object oriented programing in python and pip
LakshmiMarineni
 
PPT
Introduction to Numpy Foundation Study GuideStudyGuide
elharriettm
 
PPTX
Lecture 2 _Foundions foundions NumPyI.pptx
disserdekabrcha
 
PPTX
Introduction to numpy.pptx
ssuser0e701a
 
PPTX
NUMPY-2.pptx
MahendraVusa
 
Numpy - Array.pdf
AnkitaArjunDevkate
 
numpy code and examples with attributes.pptx
swathis752031
 
numpydocococ34554367827839271966666.pptx
sankarhariharan2007
 
Week 11.pptx
CruiseCH
 
1.NumPy is a Python library used for wor
DrAtulZende
 
NumPy.pptx
DrJasmineBeulahG
 
arraycreation.pptx
sathya930629
 
Numpy in Python.docx
manohar25689
 
Scientific Computing with Python - NumPy | WeiYuan
Wei-Yuan Chang
 
Numpy_Pandas_for beginners_________.pptx
Abhi Marvel
 
Python crash course libraries numpy-1, panda.ppt
janaki raman
 
CAP776Numpy (2).ppt
ChhaviCoachingCenter
 
CAP776Numpy.ppt
kdr52121
 
Usage of Python NumPy, 1Dim, 2Dim Arrays
NarendraDev11
 
object oriented programing in python and pip
LakshmiMarineni
 
Introduction to Numpy Foundation Study GuideStudyGuide
elharriettm
 
Lecture 2 _Foundions foundions NumPyI.pptx
disserdekabrcha
 
Introduction to numpy.pptx
ssuser0e701a
 
NUMPY-2.pptx
MahendraVusa
 
Ad

More from ToniyaP1 (6)

PPTX
Data structures: linear lists
ToniyaP1
 
PPTX
Python library
ToniyaP1
 
PPTX
Python algorithm efficency
ToniyaP1
 
PPTX
Python data file handling
ToniyaP1
 
PPTX
Python functions
ToniyaP1
 
PPTX
Python recursion
ToniyaP1
 
Data structures: linear lists
ToniyaP1
 
Python library
ToniyaP1
 
Python algorithm efficency
ToniyaP1
 
Python data file handling
ToniyaP1
 
Python functions
ToniyaP1
 
Python recursion
ToniyaP1
 

Recently uploaded (20)

PPTX
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
PPTX
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
PPTX
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
PPTX
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
PPTX
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
PPTX
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
PPTX
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PDF
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
PPTX
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
PPTX
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
PPTX
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
PPTX
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
PPTX
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
PPTX
CDH. pptx
AneetaSharma15
 
PPTX
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
PPTX
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
PPTX
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
PPTX
Care of patients with elImination deviation.pptx
AneetaSharma15
 
Command Palatte in Odoo 18.1 Spreadsheet - Odoo Slides
Celine George
 
CONCEPT OF CHILD CARE. pptx
AneetaSharma15
 
Introduction to pediatric nursing in 5th Sem..pptx
AneetaSharma15
 
Applications of matrices In Real Life_20250724_091307_0000.pptx
gehlotkrish03
 
How to Manage Leads in Odoo 18 CRM - Odoo Slides
Celine George
 
HEALTH CARE DELIVERY SYSTEM - UNIT 2 - GNM 3RD YEAR.pptx
Priyanshu Anand
 
Kanban Cards _ Mass Action in Odoo 18.2 - Odoo Slides
Celine George
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
The-Invisible-Living-World-Beyond-Our-Naked-Eye chapter 2.pdf/8th science cur...
Sandeep Swamy
 
How to Track Skills & Contracts Using Odoo 18 Employee
Celine George
 
BASICS IN COMPUTER APPLICATIONS - UNIT I
suganthim28
 
PROTIEN ENERGY MALNUTRITION: NURSING MANAGEMENT.pptx
PRADEEP ABOTHU
 
Cleaning Validation Ppt Pharmaceutical validation
Ms. Ashatai Patil
 
Continental Accounting in Odoo 18 - Odoo Slides
Celine George
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
CDH. pptx
AneetaSharma15
 
Sonnet 130_ My Mistress’ Eyes Are Nothing Like the Sun By William Shakespear...
DhatriParmar
 
An introduction to Dialogue writing.pptx
drsiddhantnagine
 
How to Close Subscription in Odoo 18 - Odoo Slides
Celine George
 
Care of patients with elImination deviation.pptx
AneetaSharma15
 

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