SlideShare a Scribd company logo
CREATING NUMPY ARRAYS
Dr. B. Subashini
Assistant Professor of Computer Applications,
V.V.Vanniaperumal College for Women,
Virudhunagar.
CREATING NUMPY ARRAYS
np.array is a function that allow users to create an array of element
supplied as an argument.
Numpy array() function takes a list of elements as argument and
returns a one-dimensional array
EX:
import numpy as np
array1 = np.array([1, 3, 5])
print("np.array():n", array1)
OUTPUT:
np.array():
[1 3 5]
NUMPY.ARRANGE
The arange([start,] stop[, step,][, dtype]) : Returns an array with evenly
spaced elements as per the interval.
EX:
import numpy as np
print("An", np.arange(4, 20, 3), "n")
OUTPUT:
A
[ 4 7 10 13 16 19]
NUMPY.LINSPACE
The numpy.linspace() function returns number spaces evenly w.r.t
interval. Similar to numpy.arange() function but instead of step it uses
sample number.
EX:
import numpy as np
a=np.linspace(1,2/3,4)
print(a)
OUTPUT:
[1 0.916666 0.83333333 0.75]
ARRAY CRATION USING LIST
Arrays are used to store multiple values in one single variable.Python
does not have built-in support for Arrays, but Python lists can be used
instead.
Example :
import numpy as np
l= [1, 2, 3, 4, 5]
arr=np.array(l)
Print(arr)
OUTPUT:
[1 2 3 4 5]
ARRAY CRATION USING TUPLE
Array values are stored in rounded brackets
Example :
import numpy as np
l= (1, 2, 3, 4, 5)
arr=np.array(l)
Print(arr)
OUTPUT:
[1 2 3 4 5]
ARRAY FUNCTIONS
NP.ONES:
creates an array filled with ones of the specified shape
Example:
import numpy as np
array3 = np.ones((2, 4))
print("nnp.ones():n", array3)
Output:
np.ones():
[[1. 1. 1. 1.]
[1. 1. 1. 1.]]
ARRAY FUNCTIONS
NP.ZEROS:
creates an array filled with zeros of the specified shape
Example:
import numpy as np
array3 = np.zeros((2, 4))
print("nnp.zeros():n", array3)
Output:
np.zeros():
[[0. 0. 0. 0.]
[0. 0. 0. 0.]]
ARRAY FUNCTIONS
NP.FULL:
creates an array filled with specified value of the specified shape
Example:
import numpy as np
array3 = np.full((2, 4),2)
print("nnp.full():n", array3)
Output:
np.full():
[[2. 2. 2. 2.]
[2. 2. 2. 2.]]
ARRAY FUNCTIONS
NUMPY.EMPTY:
The numpy.empty() function is used to create a new array of given
shape and type, without initializing entries. It is typically used for
large arrays when performance is critical, and the values will be
filled in later
Example:
import numpy as np
np.empty(2)
Output:
array([ 6.95033087e-310, 1.69970835e-316])
ARRAY FUNCTIONS
NP.RANDOM.RAND:
creates an array filled with random value of the specified shape
Example:
from numpy import random
import numpy as np
x = np.random.rand(3,2)
print(x)
Output:
[[0.19488027 0.27812108]
[0.89937813 0.20219224]
[0.21488034 0.77359958]]

More Related Content

PPTX
NUMPY LIBRARY study materials PPT 2.pptx
PPTX
NumPy.pptx
PPTX
numpy code and examples with attributes.pptx
PPTX
numpydocococ34554367827839271966666.pptx
PPTX
PPTX
Data Analyzing And Visualization Using Python.pptx
PPTX
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx
NUMPY LIBRARY study materials PPT 2.pptx
NumPy.pptx
numpy code and examples with attributes.pptx
numpydocococ34554367827839271966666.pptx
Data Analyzing And Visualization Using Python.pptx
NumPy-python-27-9-24-we.pptxNumPy-python-27-9-24-we.pptx

Similar to CREATING NUMPY ARRAYS IN PYTHON WITH AN EXAMPLE (20)

PPTX
NUMPY [Autosaved] .pptx
PPTX
1.NumPy is a Python library used for wor
PPTX
Numpy_defintion_description_usage_examples.pptx
PPTX
Introduction to numpy Session 1
PPT
CAP776Numpy (2).ppt
PPT
CAP776Numpy.ppt
PDF
Numpy - Array.pdf
PDF
Essential numpy before you start your Machine Learning journey in python.pdf
PPTX
THE NUMPY LIBRARY of python with slides.pptx
PPTX
Lecture 2 _Foundions foundions NumPyI.pptx
PPT
Introduction to Numpy Foundation Study GuideStudyGuide
PPTX
python_programming_NumPy_Pandas_Notes.pptx
PPTX
Numpy in python, Array operations using numpy and so on
PPTX
NUMPY-2.pptx
PPTX
Week 11.pptx
PDF
Python Numpy Source Codes
PDF
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
PDF
‏‏Lecture 2.pdf
PPTX
Introduction to numpy.pptx
PDF
NUMPY [Autosaved] .pptx
1.NumPy is a Python library used for wor
Numpy_defintion_description_usage_examples.pptx
Introduction to numpy Session 1
CAP776Numpy (2).ppt
CAP776Numpy.ppt
Numpy - Array.pdf
Essential numpy before you start your Machine Learning journey in python.pdf
THE NUMPY LIBRARY of python with slides.pptx
Lecture 2 _Foundions foundions NumPyI.pptx
Introduction to Numpy Foundation Study GuideStudyGuide
python_programming_NumPy_Pandas_Notes.pptx
Numpy in python, Array operations using numpy and so on
NUMPY-2.pptx
Week 11.pptx
Python Numpy Source Codes
ACFrOgAabSLW3ZCRLJ0i-To_2fPk_pA9QThyDKNNlA3VK282MnXaLGJa7APKD15-TW9zT_QI98dAH...
‏‏Lecture 2.pdf
Introduction to numpy.pptx
Ad

Recently uploaded (20)

PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
Machine learning based COVID-19 study performance prediction
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
Teaching material agriculture food technology
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
DOCX
The AUB Centre for AI in Media Proposal.docx
PPTX
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
PDF
cuic standard and advanced reporting.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Advanced methodologies resolving dimensionality complications for autism neur...
20250228 LYD VKU AI Blended-Learning.pptx
Understanding_Digital_Forensics_Presentation.pptx
Machine learning based COVID-19 study performance prediction
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Encapsulation_ Review paper, used for researhc scholars
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
Spectral efficient network and resource selection model in 5G networks
Teaching material agriculture food technology
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
The AUB Centre for AI in Media Proposal.docx
Effective Security Operations Center (SOC) A Modern, Strategic, and Threat-In...
cuic standard and advanced reporting.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Ad

CREATING NUMPY ARRAYS IN PYTHON WITH AN EXAMPLE

  • 1. CREATING NUMPY ARRAYS Dr. B. Subashini Assistant Professor of Computer Applications, V.V.Vanniaperumal College for Women, Virudhunagar.
  • 2. CREATING NUMPY ARRAYS np.array is a function that allow users to create an array of element supplied as an argument. Numpy array() function takes a list of elements as argument and returns a one-dimensional array EX: import numpy as np array1 = np.array([1, 3, 5]) print("np.array():n", array1) OUTPUT: np.array(): [1 3 5]
  • 3. NUMPY.ARRANGE The arange([start,] stop[, step,][, dtype]) : Returns an array with evenly spaced elements as per the interval. EX: import numpy as np print("An", np.arange(4, 20, 3), "n") OUTPUT: A [ 4 7 10 13 16 19]
  • 4. NUMPY.LINSPACE The numpy.linspace() function returns number spaces evenly w.r.t interval. Similar to numpy.arange() function but instead of step it uses sample number. EX: import numpy as np a=np.linspace(1,2/3,4) print(a) OUTPUT: [1 0.916666 0.83333333 0.75]
  • 5. ARRAY CRATION USING LIST Arrays are used to store multiple values in one single variable.Python does not have built-in support for Arrays, but Python lists can be used instead. Example : import numpy as np l= [1, 2, 3, 4, 5] arr=np.array(l) Print(arr) OUTPUT: [1 2 3 4 5]
  • 6. ARRAY CRATION USING TUPLE Array values are stored in rounded brackets Example : import numpy as np l= (1, 2, 3, 4, 5) arr=np.array(l) Print(arr) OUTPUT: [1 2 3 4 5]
  • 7. ARRAY FUNCTIONS NP.ONES: creates an array filled with ones of the specified shape Example: import numpy as np array3 = np.ones((2, 4)) print("nnp.ones():n", array3) Output: np.ones(): [[1. 1. 1. 1.] [1. 1. 1. 1.]]
  • 8. ARRAY FUNCTIONS NP.ZEROS: creates an array filled with zeros of the specified shape Example: import numpy as np array3 = np.zeros((2, 4)) print("nnp.zeros():n", array3) Output: np.zeros(): [[0. 0. 0. 0.] [0. 0. 0. 0.]]
  • 9. ARRAY FUNCTIONS NP.FULL: creates an array filled with specified value of the specified shape Example: import numpy as np array3 = np.full((2, 4),2) print("nnp.full():n", array3) Output: np.full(): [[2. 2. 2. 2.] [2. 2. 2. 2.]]
  • 10. ARRAY FUNCTIONS NUMPY.EMPTY: The numpy.empty() function is used to create a new array of given shape and type, without initializing entries. It is typically used for large arrays when performance is critical, and the values will be filled in later Example: import numpy as np np.empty(2) Output: array([ 6.95033087e-310, 1.69970835e-316])
  • 11. ARRAY FUNCTIONS NP.RANDOM.RAND: creates an array filled with random value of the specified shape Example: from numpy import random import numpy as np x = np.random.rand(3,2) print(x) Output: [[0.19488027 0.27812108] [0.89937813 0.20219224] [0.21488034 0.77359958]]