SlideShare uma empresa Scribd logo
1 de 5
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a Numpy

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxRamakrishna Reddy Bijjam
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structuredhanjurrannsibayan2
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
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
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the ClassroomPooky Knightsmith
 
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
 
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
 
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
 
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
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxVishalSingh1417
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.MaryamAhmad92
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701bronxfugly43
 
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
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...ZurliaSoop
 
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
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Association for Project Management
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.christianmathematics
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxEsquimalt MFRC
 

Último (20)

Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
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
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
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
 
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
 
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
 
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
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.ICT role in 21st century education and it's challenges.
ICT role in 21st century education and it's challenges.
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
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
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
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
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).pptxHMCS Max Bernays Pre-Deployment Brief (May 2024).pptx
HMCS Max Bernays Pre-Deployment Brief (May 2024).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