SlideShare a Scribd company logo
1 of 26
Download to read offline
Arrays in Python
Moazam Ali
Arrays
 Array is basically a data structure which can hold more than one value at a time.
 It is a collection or ordered series of items at same time
 Each item stored in an array is called an element.
 Each location of an element in an array has a numerical index, which is used to
identify the element.
 Format: array_name = array(‘type_code’,[initializer])
Type Code
Typecode Value
b Represents signed integer of size 1
byte/td>
B Represents unsigned integer of size 1
byte
c Represents character of size 1 byte
i Represents signed integer of size 2
bytes
I Represents unsigned integer of size 2
bytes
f Represents floating point of size 4
bytes
d Represents floating point of size 8
bytes
 Arrays in Python can be created after importing the array module
 There are three methods to import array library
import array
Import array as arr
from array import *
How to create an Arrays in Python
Accessing Array Element
 Accessing elements using index value
 Index starts from 0 to n-1where n is the number of elements
 -ive index value can be used as well, -ive indexing starts from reverse order
0 1 2 3 4 5
Example
import array as arr
a = arr.array('i', [2, 4, 6, 8])
print("First element:", a[0])
print("Second element:", a[1])
print("last element:", a[-1])
Output
First element is: 2
Second element: 4
last element: 8
Basic Array Operations
 Finding the length of an array
 Adding/Changing element of an array
 Removing/deleting element of an array
 Array concatenation
 Slicing
 Looping through an array
 sorting
Finding the length of an array
 Number of element present in the array
 Using len() function to find the length
 The len() function returns an integer value that is equal to the number of elements
present in that array
Finding the length of an array
 Syntax
 Example
from array import *
a = array('i', [2, 4, 6, 8])
print(len(a)) output
4
len(array_name)
Adding elements to an array
 Using functions to add elements
 append() is used to add a single element at the end of an array
 extend() is used to add a more than one element at the end of an array
 insert() is used to add an element at the specific position in an array
Example
from array import *
numbers = array('i', [1, 2, 3])
numbers.append(4)
print(numbers)
numbers.extend([5, 6, 7])
print(numbers)
numbers.insert(3,8)
print(numbers)
 Output
array('i', [1, 2, 3, 4])
array('i', [1, 2, 3, 4, 5, 6, 7])
array('i', [1, 2, 3, 8, 4, 5, 6, 7])
Removing elements of an array
 Functions used to removing elements of an array
 pop() is used when we want to remove an element and return it.
 remove() is used when we want to remove an element with a specific value
without returning it.
Example
import array as arr
numbers = arr.array('i', [10, 11, 12, 12, 13])
numbers.remove(12)
print(numbers) # Output: array('i', [10, 11, 12, 13])
numbers.pop(2) # Output: 12
print(numbers)
Arrays Concatenation
 Arrays concatenation is done using + sign
 Example
import array as n
a = n.array('i', [10, 11, 12, 12, 13])
b = n.array('i', [21, 22, 35, 26,39])
c=a+b
print(c) output
array('i', [10, 11, 12, 12, 13, 21, 22, 35, 26, 39])
Slicing an array
 An array can be sliced using the : symbol
 This returns a range of elements that we have specified by the index number
 Example
import array as arr
numbers_list = [2, 5, 62, 5, 42, 52, 48, 5]
numbers_array = arr.array('i', numbers_list)
print(numbers_array[2:5]) # 3rd to 5th
print(numbers_array[:-5]) # beginning to 5th
print(numbers_array[5:]) # 6th to end
print(numbers_array[:]) # beginning to end
Looping through an array
 For loop used to iterates over the items of an array specified number of
times
 While loop iterates the elements until a certain condition is met
 Example
from array import *
numbers_list = [2, 5, 62, 5, 42, 52, 48, ]
a = array('i', numbers_list)
for x in a:
print(x)
Sorting of an array
 sort the elements of the array in ascending order
 Use sorted() buit in function to sort the array
 Format: sorted(array_name)
Example
from array import *
a = array('i',[4,3,6,2,1])
b=sorted(a)
for x in b:
print(x)
Output:
1
2
3
4
6
Sorting of array in descending order
 Format: sorted(array_name, reverse=true)
 Example:
from array import * output:
a = array('i',[4,3,6,2,1]) 6
b=sorted(a, reverse=true) 4
for x in b: 3
print(x) 2
1
Array Methods
 Python has a set of built-in methods that you can use on lists/arrays.
Method Description
append() Adds an element at the end of the list
clear() Removes all the elements from the list
copy() Returns a copy of the list
count() Returns the number of elements with the specified value
extend() Add the elements of a list (or any iterable), to the end of the
current list
index() Returns the index of the first element with the specified value
insert() Adds an element at the specified position
pop() Removes the element at the specified position
remove() Removes the first item with the specified value
reverse() Reverses the order of the list
sort() Sorts the list
TYPES OF ARRAYS
 As we know that arrays are of 3 types which include
 1D Array
 2D Array
 Multi D Array
In python we use
Package Numpy
We have to install it using python tools(PIP)
First of all import library that is numpy as np
Import numpy
 There are three methods to import numpy
import numpy
import numpy as np
from numpy import *
Example 1 D Array
# 1D Array
Import numpy as np
a = np.array([10,20,30,40,50])
print (a)
 Output
array([10,20,30,40,50])
Example 2D Array
Import numpy as np
#2D Array
#3x3 Array
B=np.array([
[10,20,30,],
[40,50,60],
[70,80,90]])
print (b)
Example 3D Array
Import numpy as np
# 3D Array
# 3x3x3
C=np.array([
[[1,2,3],[4,5,6],[7,8,9]],
[[9,8,7],[6,5,4],[3,2,1]],
[[1,2,3],[4,5,6],[7,8,9]]
])
Print (c)

More Related Content

What's hot (20)

Sets in python
Sets in pythonSets in python
Sets in python
 
Queue in Data Structure
Queue in Data Structure Queue in Data Structure
Queue in Data Structure
 
Arrays
ArraysArrays
Arrays
 
Queue data structure
Queue data structureQueue data structure
Queue data structure
 
Python programming : List and tuples
Python programming : List and tuplesPython programming : List and tuples
Python programming : List and tuples
 
Functions in python slide share
Functions in python slide shareFunctions in python slide share
Functions in python slide share
 
Functions in Python
Functions in PythonFunctions in Python
Functions in Python
 
This pointer
This pointerThis pointer
This pointer
 
Data types in python
Data types in pythonData types in python
Data types in python
 
Array Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional arrayArray Introduction One-dimensional array Multidimensional array
Array Introduction One-dimensional array Multidimensional array
 
Queue ppt
Queue pptQueue ppt
Queue ppt
 
Array in Java
Array in JavaArray in Java
Array in Java
 
Datastructures in python
Datastructures in pythonDatastructures in python
Datastructures in python
 
Python Functions
Python   FunctionsPython   Functions
Python Functions
 
Python Modules
Python ModulesPython Modules
Python Modules
 
Introduction to NumPy
Introduction to NumPyIntroduction to NumPy
Introduction to NumPy
 
C++ Arrays
C++ ArraysC++ Arrays
C++ Arrays
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
Queue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked ListQueue Implementation Using Array & Linked List
Queue Implementation Using Array & Linked List
 
Python : Data Types
Python : Data TypesPython : Data Types
Python : Data Types
 

Similar to Arrays in python (20)

ARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptxARRAY OPERATIONS.pptx
ARRAY OPERATIONS.pptx
 
16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues16. Arrays Lists Stacks Queues
16. Arrays Lists Stacks Queues
 
ACP-arrays.pptx
ACP-arrays.pptxACP-arrays.pptx
ACP-arrays.pptx
 
9781439035665 ppt ch09
9781439035665 ppt ch099781439035665 ppt ch09
9781439035665 ppt ch09
 
Python array
Python arrayPython array
Python array
 
SlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdfSlideSet_4_Arraysnew.pdf
SlideSet_4_Arraysnew.pdf
 
Chap09
Chap09Chap09
Chap09
 
Unit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTUREUnit 2 dsa LINEAR DATA STRUCTURE
Unit 2 dsa LINEAR DATA STRUCTURE
 
Numpy in Python.docx
Numpy in Python.docxNumpy in Python.docx
Numpy in Python.docx
 
Array assignment
Array assignmentArray assignment
Array assignment
 
arrays.pptx
arrays.pptxarrays.pptx
arrays.pptx
 
Arrays
ArraysArrays
Arrays
 
Arrays in C++
Arrays in C++Arrays in C++
Arrays in C++
 
ARRAYS
ARRAYSARRAYS
ARRAYS
 
NUMPY-2.pptx
NUMPY-2.pptxNUMPY-2.pptx
NUMPY-2.pptx
 
07 Arrays
07 Arrays07 Arrays
07 Arrays
 
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
 
Arrays_in_c++.pptx
Arrays_in_c++.pptxArrays_in_c++.pptx
Arrays_in_c++.pptx
 
DS Unit 1.pptx
DS Unit 1.pptxDS Unit 1.pptx
DS Unit 1.pptx
 

Recently uploaded

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Velvetech LLC
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanyChristoph Pohl
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odishasmiwainfosol
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作qr0udbr0
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Matt Ray
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesPhilip Schwarz
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfLivetecs LLC
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 

Recently uploaded (20)

Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...Software Project Health Check: Best Practices and Techniques for Your Product...
Software Project Health Check: Best Practices and Techniques for Your Product...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte GermanySuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
SuccessFactors 1H 2024 Release - Sneak-Peek by Deloitte Germany
 
2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva2.pdf Ejercicios de programación competitiva
2.pdf Ejercicios de programación competitiva
 
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company OdishaBalasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
Balasore Best It Company|| Top 10 IT Company || Balasore Software company Odisha
 
英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作英国UN学位证,北安普顿大学毕业证书1:1制作
英国UN学位证,北安普顿大学毕业证书1:1制作
 
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
Open Source Summit NA 2024: Open Source Cloud Costs - OpenCost's Impact on En...
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Folding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a seriesFolding Cheat Sheet #4 - fourth in a series
Folding Cheat Sheet #4 - fourth in a series
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
How to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdfHow to Track Employee Performance A Comprehensive Guide.pdf
How to Track Employee Performance A Comprehensive Guide.pdf
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort ServiceHot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
Hot Sexy call girls in Patel Nagar🔝 9953056974 🔝 escort Service
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 

Arrays in python

  • 2. Arrays  Array is basically a data structure which can hold more than one value at a time.  It is a collection or ordered series of items at same time  Each item stored in an array is called an element.  Each location of an element in an array has a numerical index, which is used to identify the element.  Format: array_name = array(‘type_code’,[initializer])
  • 3. Type Code Typecode Value b Represents signed integer of size 1 byte/td> B Represents unsigned integer of size 1 byte c Represents character of size 1 byte i Represents signed integer of size 2 bytes I Represents unsigned integer of size 2 bytes f Represents floating point of size 4 bytes d Represents floating point of size 8 bytes
  • 4.  Arrays in Python can be created after importing the array module  There are three methods to import array library import array Import array as arr from array import * How to create an Arrays in Python
  • 5. Accessing Array Element  Accessing elements using index value  Index starts from 0 to n-1where n is the number of elements  -ive index value can be used as well, -ive indexing starts from reverse order 0 1 2 3 4 5
  • 6. Example import array as arr a = arr.array('i', [2, 4, 6, 8]) print("First element:", a[0]) print("Second element:", a[1]) print("last element:", a[-1]) Output First element is: 2 Second element: 4 last element: 8
  • 7. Basic Array Operations  Finding the length of an array  Adding/Changing element of an array  Removing/deleting element of an array  Array concatenation  Slicing  Looping through an array  sorting
  • 8. Finding the length of an array  Number of element present in the array  Using len() function to find the length  The len() function returns an integer value that is equal to the number of elements present in that array
  • 9. Finding the length of an array  Syntax  Example from array import * a = array('i', [2, 4, 6, 8]) print(len(a)) output 4 len(array_name)
  • 10. Adding elements to an array  Using functions to add elements  append() is used to add a single element at the end of an array  extend() is used to add a more than one element at the end of an array  insert() is used to add an element at the specific position in an array
  • 11. Example from array import * numbers = array('i', [1, 2, 3]) numbers.append(4) print(numbers) numbers.extend([5, 6, 7]) print(numbers) numbers.insert(3,8) print(numbers)
  • 12.  Output array('i', [1, 2, 3, 4]) array('i', [1, 2, 3, 4, 5, 6, 7]) array('i', [1, 2, 3, 8, 4, 5, 6, 7])
  • 13. Removing elements of an array  Functions used to removing elements of an array  pop() is used when we want to remove an element and return it.  remove() is used when we want to remove an element with a specific value without returning it.
  • 14. Example import array as arr numbers = arr.array('i', [10, 11, 12, 12, 13]) numbers.remove(12) print(numbers) # Output: array('i', [10, 11, 12, 13]) numbers.pop(2) # Output: 12 print(numbers)
  • 15. Arrays Concatenation  Arrays concatenation is done using + sign  Example import array as n a = n.array('i', [10, 11, 12, 12, 13]) b = n.array('i', [21, 22, 35, 26,39]) c=a+b print(c) output array('i', [10, 11, 12, 12, 13, 21, 22, 35, 26, 39])
  • 16. Slicing an array  An array can be sliced using the : symbol  This returns a range of elements that we have specified by the index number  Example import array as arr numbers_list = [2, 5, 62, 5, 42, 52, 48, 5] numbers_array = arr.array('i', numbers_list) print(numbers_array[2:5]) # 3rd to 5th print(numbers_array[:-5]) # beginning to 5th print(numbers_array[5:]) # 6th to end print(numbers_array[:]) # beginning to end
  • 17. Looping through an array  For loop used to iterates over the items of an array specified number of times  While loop iterates the elements until a certain condition is met  Example from array import * numbers_list = [2, 5, 62, 5, 42, 52, 48, ] a = array('i', numbers_list) for x in a: print(x)
  • 18. Sorting of an array  sort the elements of the array in ascending order  Use sorted() buit in function to sort the array  Format: sorted(array_name)
  • 19. Example from array import * a = array('i',[4,3,6,2,1]) b=sorted(a) for x in b: print(x) Output: 1 2 3 4 6
  • 20. Sorting of array in descending order  Format: sorted(array_name, reverse=true)  Example: from array import * output: a = array('i',[4,3,6,2,1]) 6 b=sorted(a, reverse=true) 4 for x in b: 3 print(x) 2 1
  • 21. Array Methods  Python has a set of built-in methods that you can use on lists/arrays. Method Description append() Adds an element at the end of the list clear() Removes all the elements from the list copy() Returns a copy of the list count() Returns the number of elements with the specified value extend() Add the elements of a list (or any iterable), to the end of the current list index() Returns the index of the first element with the specified value insert() Adds an element at the specified position pop() Removes the element at the specified position remove() Removes the first item with the specified value reverse() Reverses the order of the list sort() Sorts the list
  • 22. TYPES OF ARRAYS  As we know that arrays are of 3 types which include  1D Array  2D Array  Multi D Array In python we use Package Numpy We have to install it using python tools(PIP) First of all import library that is numpy as np
  • 23. Import numpy  There are three methods to import numpy import numpy import numpy as np from numpy import *
  • 24. Example 1 D Array # 1D Array Import numpy as np a = np.array([10,20,30,40,50]) print (a)  Output array([10,20,30,40,50])
  • 25. Example 2D Array Import numpy as np #2D Array #3x3 Array B=np.array([ [10,20,30,], [40,50,60], [70,80,90]]) print (b)
  • 26. Example 3D Array Import numpy as np # 3D Array # 3x3x3 C=np.array([ [[1,2,3],[4,5,6],[7,8,9]], [[9,8,7],[6,5,4],[3,2,1]], [[1,2,3],[4,5,6],[7,8,9]] ]) Print (c)