0% found this document useful (0 votes)
69 views

Numpy

Uploaded by

bansalshreya904
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

Numpy

Uploaded by

bansalshreya904
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 14

INTRODUCTION TO

NUMPY
BY HARSH BANSAL AND AKSHAT MANGAL
WHAT IS NUMPY?
• NumPy is a Python library used for working with arrays.
• It also has functions for working in domain of linear algebra, fourier
transform, and matrices.
WHY NUMPY NOT LIST ?
• In Python we have lists that serve the purpose of arrays, but they are
slow to process.
• NumPy aims to provide an array object that is up to 50x faster than
traditional Python lists.
• NumPy arrays are stored at one continuous place in memory unlike
lists, so processes can access and manipulate them very efficiently.
• This is the main reason why NumPy is faster than lists. Also it is
optimized to work with latest CPU architectures.
NUMPY CREATING ARRAYS

• We can create a NumPy ndarray object by using the array() function.


Output:

type(): This built-in Python function tells us the type of the object passed to it. Like in above code it shows
that arr is numpy.ndarray type.
• Create a 2-D array containing two arrays with the values 1,2,3 and 4,5,6:

Code:

Output:
NUMPY ARRAY FUNCTIONS

• np.size() - Returns the total number of elements in the array..


Exampl
e:

• a.shape - It can be used to determine the size of each dimension of an


array. Example
:

Output:
NUMPY ARRAY FUNCTIONS

• np.arange() - Return evenly spaced values within a given range.


Exampl
e:
• np.ones() - Create an array filled with ones.
Example
:
• np.zeros() - Create an array filled with zeros.
Exampl
e:
NUMPY ARRAY FUNCTIONS

• np.eye() - Create a 2D identity matrix.


Exampl
e:

• np.full() - Create an array of a given shape and fill it with a specified


value. Example
:
NUMPY ARRAY FUNCTIONS

• np.ndim() - Returns the number of dimensions (axes) in the array.


Exampl
e:
NUMPY ARRAY FUNCTIONS

• np.random.random() - Generate random numbers from a uniform


distribution Exampl
between 0 and 1.
e:

• a.dtype – It determine the data type of element in numpy array


Example: Input: a.dtype
output: dtype( ‘int32’ )
NUMPY FUNCTIONS

np.reshape()
:
NUMPY ARRAY SLICING

Slicing in python means taking elements from one given index to another
given index.
We pass slice instead of index like this: [start:end].
We can also define the step, like this: [start:end:step].
If we don't pass start its considered 0
If we don't pass end its considered length of array in that dimension
If we don't pass step its considered 1
• Example: Output
NUMPY OPERATIONS

Addition

Subtraction

Multiplication

Divison
NUMPY OPERATION

Power of ndarrays: Matrix Multiplication:

You might also like