SlideShare a Scribd company logo
Array :
Arrays are fundamental part of most programming languages. It is the collection of
elements of a single data type, eg. array of int, array of string.
However, in Python, there is no native array data structure. So, we use Python
lists instead of an array.
Note: If you want to create real arrays in Python, you need to use NumPy's
array data structure. For mathematical problems, NumPy Array is more efficient.
Unlike arrays, a single list can store elements of any data type and does everything
an array does. We can store an integer, a float and a string inside the same list. So,
it is more flexible to work with.
[10, 20, 30, 40, 50 ] is an example of what an array would look like in Python, but
it is actually a list.
import array
A=array.array('i',[4,3,2,5])
print(A)
print(type(A))
import array as arr
A=arr.array('i',[4,3,2,5])
print(A)
from array import *
A=array('i',[4,3,2,5])
print(A)
from array import *
A=array('i',[4,3,2,5])
print(A)
print(type(A))
print(A.typecode)
print(A.buffer_info())
print(A.remove(A[2]))
print(A)
print(A.append(33))
print(A)
print(A.reverse())
print(A)
for i in range(4):
print(A[i])
for i in range(len(A)):
print(A[i])
#copying Array
from array import *
A=array('i',[2,3,4,5])
print(A)
B=array(A.typecode,(i*i for i in
A))
print(B)
#character array
from array import *
A=array('u',['m','o','h','a','n']
)
print(A)
# Accepting the values from user and print Array:
from array import *
arr=array('i',[])
n=int(input("Enter Length of
Array"))
for i in range(n):
x=int(input("Enter the next
value:"))
arr.append(x)
print(arr)
s=int(input("Enter the value for
search:"))
#searchinng element in Array
print(arr.index(s))
What is NumPy?
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.
 In NumPy dimensions are called axes. The number of axes is rank.
To create multi dimension Array in python we use Numpy.
To Install Numpy in command prompt:
Goto command prompt and type : pip3 install numpy
To Install Numpy in Pycharm:
Goto Pycharm Editor
Click on File
Click on settings
Expand Project
Click on Project Interpreter
Click on + Symbol from RHS(Right Hand Side)
Type numpy in search
Choose numpy
Then Click on install numpy package.
Creating Multi dimension Array In different ways like:
Array()
Linespace()
Logspace()
Arange()
Zeros()
Ones()
EX:
Array():
from numpy import *
arr=array([1,2,3,4,5])
print(arr)
print(arr.dtype)
from numpy import *
arr=array([1,2,3,4.7,5])
print(arr)
print(arr.dtype)
from numpy import *
arr=array([1,2,3,4.7,5],int)
print(arr)
print(arr.dtype)
Linespace()
from numpy import *
arr=linspace(0,10,11)#
start,stop,no of parts
print(arr)
Logspace()
from numpy import *
arr=logspace(1,20,5)#
start,stop,no of parts
print(arr)
Arange()
from numpy import *
arr=arange(1,20,2)#
start,stop,step
print(arr)
Zeros()
from numpy import *
arr=zeros(6,int)
print(arr)
Ones()
from numpy import *
arr=ones(6,int)
print(arr)
Creating Multidimension Array:
import numpy as np
#creating array
arr=np.array([[1,2,3],
[4,5,6]])
#printing type of array
print("Array type is:",type(arr))
# Printing array dimensions
(axes)
print("No. of dimensions: ",
arr.ndim)
# Printing shape of array
print("Shape of array: ",
arr.shape)
# Printing size (total number of
elements) of array
print("Size of array: ",
arr.size)
# Printing type of elements in
array
print("Array stores elements of
type: ", arr.dtype)
We can use flatten method to get a copy of array collapsed into one dimension. It
accepts order argument.
import numpy as np
#creating array
arr=np.array([[1,2,3],
[4,5,6]])
flat = arr.flatten()
print(flat)
Basic Operations in Multi dimension Array:
# unary operators in numpy
import numpy as np
arr = np.array([[1, 5, 6],
[4, 7, 2],
[3, 1, 9]])
# maximum element of array
print("Largest element is:",
arr.max())
print("Row-wise maximum
elements:",
arr.max(axis=1))
# minimum element of array
print("Column-wise minimum
elements:",
arr.min(axis=0))
# sum of array elements
print("Sum of all array
elements:",
arr.sum())

More Related Content

PPTX
object oriented programing in python and pip
LakshmiMarineni
 
PPTX
1.NumPy is a Python library used for wor
DrAtulZende
 
PPTX
NUMPY [Autosaved] .pptx
coolmanbalu123
 
PPTX
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
tahirnaquash2
 
PPTX
NUMPY-2.pptx
MahendraVusa
 
PPTX
Numpy in python, Array operations using numpy and so on
SherinRappai
 
PDF
Arrays in python
moazamali28
 
object oriented programing in python and pip
LakshmiMarineni
 
1.NumPy is a Python library used for wor
DrAtulZende
 
NUMPY [Autosaved] .pptx
coolmanbalu123
 
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
tahirnaquash2
 
NUMPY-2.pptx
MahendraVusa
 
Numpy in python, Array operations using numpy and so on
SherinRappai
 
Arrays in python
moazamali28
 

Similar to Numpy in Python.docx (20)

PPTX
NumPy.pptx
DrJasmineBeulahG
 
PDF
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
DineshThallapelly
 
PDF
Essential numpy before you start your Machine Learning journey in python.pdf
Smrati Kumar Katiyar
 
PPTX
Data Preprocessing Introduction for Machine Learning
sonali sonavane
 
PDF
Unit-5-Part1 Array in Python programming.pdf
582004rohangautam
 
PPTX
NumPy.pptx
EN1036VivekSingh
 
PPTX
Presentation1.pptxvghvfhgvbn nbnmbnbjkbjkbjib
RahinTamboli
 
PPTX
arraycreation.pptx
sathya930629
 
PPTX
Numpy _
SwatiHans10
 
PDF
Python programming : Arrays
Emertxe Information Technologies Pvt Ltd
 
PPTX
ARRAY OPERATIONS.pptx
DarellMuchoko
 
PPTX
Array-single dimensional array concept .pptx
SindhuVelmukull
 
PDF
Numpy - Array.pdf
AnkitaArjunDevkate
 
PPTX
Python1_Extracted_PDF_20250404_1054.pptx
ecomwithfaith
 
PPTX
In Python, a list is a built-in dynamic sized array. We can store all types o...
Karthik Rohan
 
PPT
CAP776Numpy.ppt
kdr52121
 
PPT
CAP776Numpy (2).ppt
ChhaviCoachingCenter
 
PPTX
Data Analyzing And Visualization Using Python.pptx
PoojaChavan51
 
PPTX
numpy code and examples with attributes.pptx
swathis752031
 
PPTX
numpydocococ34554367827839271966666.pptx
sankarhariharan2007
 
NumPy.pptx
DrJasmineBeulahG
 
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
DineshThallapelly
 
Essential numpy before you start your Machine Learning journey in python.pdf
Smrati Kumar Katiyar
 
Data Preprocessing Introduction for Machine Learning
sonali sonavane
 
Unit-5-Part1 Array in Python programming.pdf
582004rohangautam
 
NumPy.pptx
EN1036VivekSingh
 
Presentation1.pptxvghvfhgvbn nbnmbnbjkbjkbjib
RahinTamboli
 
arraycreation.pptx
sathya930629
 
Numpy _
SwatiHans10
 
Python programming : Arrays
Emertxe Information Technologies Pvt Ltd
 
ARRAY OPERATIONS.pptx
DarellMuchoko
 
Array-single dimensional array concept .pptx
SindhuVelmukull
 
Numpy - Array.pdf
AnkitaArjunDevkate
 
Python1_Extracted_PDF_20250404_1054.pptx
ecomwithfaith
 
In Python, a list is a built-in dynamic sized array. We can store all types o...
Karthik Rohan
 
CAP776Numpy.ppt
kdr52121
 
CAP776Numpy (2).ppt
ChhaviCoachingCenter
 
Data Analyzing And Visualization Using Python.pptx
PoojaChavan51
 
numpy code and examples with attributes.pptx
swathis752031
 
numpydocococ34554367827839271966666.pptx
sankarhariharan2007
 
Ad

More from manohar25689 (6)

DOCX
Multi Threading.docx
manohar25689
 
DOCX
Modules in Python.docx
manohar25689
 
DOCX
Logging in Python.docx
manohar25689
 
DOCX
controlstatementspy.docx
manohar25689
 
DOCX
List Data Structure.docx
manohar25689
 
DOCX
File Handling in python.docx
manohar25689
 
Multi Threading.docx
manohar25689
 
Modules in Python.docx
manohar25689
 
Logging in Python.docx
manohar25689
 
controlstatementspy.docx
manohar25689
 
List Data Structure.docx
manohar25689
 
File Handling in python.docx
manohar25689
 
Ad

Recently uploaded (20)

PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PPTX
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
PPTX
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
PPTX
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
PDF
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPTX
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
PDF
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
PPTX
Congenital Hypothyroidism pptx
AneetaSharma15
 
PPTX
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PDF
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
PDF
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
PPT
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
DOCX
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
DOCX
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
PDF
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
IMMUNIZATION PROGRAMME pptx
AneetaSharma15
 
PREVENTIVE PEDIATRIC. pptx
AneetaSharma15
 
Information Texts_Infographic on Forgetting Curve.pptx
Tata Sevilla
 
5.EXPLORING-FORCES-Detailed-Notes.pdf/8TH CLASS SCIENCE CURIOSITY
Sandeep Swamy
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Five Point Someone – Chetan Bhagat | Book Summary & Analysis by Bhupesh Kushwaha
Bhupesh Kushwaha
 
Exploring-Forces 5.pdf/8th science curiosity/by sandeep swamy notes/ppt
Sandeep Swamy
 
Congenital Hypothyroidism pptx
AneetaSharma15
 
Odoo 18 Sales_ Managing Quotation Validity
Celine George
 
vedic maths in python:unleasing ancient wisdom with modern code
mistrymuskan14
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
UTS Health Student Promotional Representative_Position Description.pdf
Faculty of Health, University of Technology Sydney
 
The Minister of Tourism, Culture and Creative Arts, Abla Dzifa Gomashie has e...
nservice241
 
Python Programming Unit II Control Statements.ppt
CUO VEERANAN VEERANAN
 
SAROCES Action-Plan FOR ARAL PROGRAM IN DEPED
Levenmartlacuna1
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
Action Plan_ARAL PROGRAM_ STAND ALONE SHS.docx
Levenmartlacuna1
 
1.Natural-Resources-and-Their-Use.ppt pdf /8th class social science Exploring...
Sandeep Swamy
 

Numpy in Python.docx

  • 1. Array : Arrays are fundamental part of most programming languages. It is the collection of elements of a single data type, eg. array of int, array of string. However, in Python, there is no native array data structure. So, we use Python lists instead of an array. Note: If you want to create real arrays in Python, you need to use NumPy's array data structure. For mathematical problems, NumPy Array is more efficient. Unlike arrays, a single list can store elements of any data type and does everything an array does. We can store an integer, a float and a string inside the same list. So, it is more flexible to work with. [10, 20, 30, 40, 50 ] is an example of what an array would look like in Python, but it is actually a list. import array A=array.array('i',[4,3,2,5]) print(A) print(type(A))
  • 2. import array as arr A=arr.array('i',[4,3,2,5]) print(A) from array import * A=array('i',[4,3,2,5]) print(A) from array import * A=array('i',[4,3,2,5]) print(A) print(type(A)) print(A.typecode) print(A.buffer_info()) print(A.remove(A[2])) print(A) print(A.append(33)) print(A) print(A.reverse()) print(A) for i in range(4): print(A[i]) for i in range(len(A)): print(A[i])
  • 3. #copying Array from array import * A=array('i',[2,3,4,5]) print(A) B=array(A.typecode,(i*i for i in A)) print(B) #character array from array import * A=array('u',['m','o','h','a','n'] ) print(A) # Accepting the values from user and print Array: from array import * arr=array('i',[]) n=int(input("Enter Length of Array")) for i in range(n): x=int(input("Enter the next value:")) arr.append(x) print(arr)
  • 4. s=int(input("Enter the value for search:")) #searchinng element in Array print(arr.index(s)) What is NumPy? 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.  In NumPy dimensions are called axes. The number of axes is rank. To create multi dimension Array in python we use Numpy. To Install Numpy in command prompt: Goto command prompt and type : pip3 install numpy To Install Numpy in Pycharm: Goto Pycharm Editor Click on File Click on settings Expand Project Click on Project Interpreter Click on + Symbol from RHS(Right Hand Side) Type numpy in search Choose numpy Then Click on install numpy package.
  • 5. Creating Multi dimension Array In different ways like: Array() Linespace() Logspace() Arange() Zeros() Ones() EX: Array(): from numpy import * arr=array([1,2,3,4,5]) print(arr) print(arr.dtype) from numpy import * arr=array([1,2,3,4.7,5]) print(arr) print(arr.dtype) from numpy import * arr=array([1,2,3,4.7,5],int) print(arr) print(arr.dtype) Linespace()
  • 6. from numpy import * arr=linspace(0,10,11)# start,stop,no of parts print(arr) Logspace() from numpy import * arr=logspace(1,20,5)# start,stop,no of parts print(arr) Arange() from numpy import * arr=arange(1,20,2)# start,stop,step print(arr) Zeros() from numpy import * arr=zeros(6,int) print(arr) Ones()
  • 7. from numpy import * arr=ones(6,int) print(arr) Creating Multidimension Array: import numpy as np #creating array arr=np.array([[1,2,3], [4,5,6]]) #printing type of array print("Array type is:",type(arr)) # Printing array dimensions (axes) print("No. of dimensions: ", arr.ndim) # Printing shape of array print("Shape of array: ", arr.shape) # Printing size (total number of elements) of array print("Size of array: ", arr.size) # Printing type of elements in array
  • 8. print("Array stores elements of type: ", arr.dtype) We can use flatten method to get a copy of array collapsed into one dimension. It accepts order argument. import numpy as np #creating array arr=np.array([[1,2,3], [4,5,6]]) flat = arr.flatten() print(flat) Basic Operations in Multi dimension Array: # unary operators in numpy import numpy as np arr = np.array([[1, 5, 6], [4, 7, 2], [3, 1, 9]]) # maximum element of array print("Largest element is:", arr.max()) print("Row-wise maximum elements:", arr.max(axis=1))
  • 9. # minimum element of array print("Column-wise minimum elements:", arr.min(axis=0)) # sum of array elements print("Sum of all array elements:", arr.sum())