NumPy.pptx

BhavaniGovardhan 428 views 15 slides Dec 17, 2022
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

Introduction to NumPy, NumPy Installation, Data Types, NumPy ndarray, Basic Indexing and Slicing, Boolean Indexing, Fancy Indexing, Data Processing using Arrays, Expressing Conditional Logic, Methods for Boolean Arrays, Sorting, Unique.


Slide Content

Introduction to NumPy

Introduction NumPy is a Python package. It stands for 'Numerical Python'. It is a library consisting of multidimensional array objects and a collection of routines for processing of array.

NumPy Installation Open command prompt and set current working directory as C:\Users\UserName\AppData\Local\Programs\Python\Python310\Scripts> Then enter the following command pip install numpy

Data Types Python have strings, integer, float, boolean and complex. NumPy has some extra data types, and refer to data types with following character: i - integer M - datetime b - boolean O - object u - unsigned integer S - string f - float U - unicode string c - complex float V - fixed chunk of memory for other type (void) m - timedelta

NumPy Basics np.arange () - used to get evenly spaced values within a given interval. numpy.arange ([start, ]stop, [step, ] dtype =None) numpy.random.random () - used to generate random floats number in the half-open interval (0.0, 1.0). numpy.random.random ([size])

NumPy-ndarray NumPy is an N-dimensional array type called ndarray . It describes the collection of items of the same type. numpy.array (object, dtype = None, copy = True, order = None, subok = False, ndmin = 0)

Basic Indexing and Slicing Contents of ndarray object can be accessed and modified by indexing or slicing, just like Python's in-built container objects. slice( start,stop,step )

Boolean Indexing You can index specific values from a  NumPy  array using another NumPy array of Boolean values on one axis to specify the indices you want to access.

Fancy Indexing NumPy provides you with a convenient way to index an array called  fancy indexing . Fancy indexing allows you to index a numpy array using the following: Another numpy array A Python  list

Data Processing using Arrays With the  NumPy package, we can easily solve many kinds of data processing tasks without writing complex loops. NumPy contains a large number of various mathematical operations arithmetic operations, trigonometric functions, handling complex numbers, etc.

Cont… Arithmetic Operations: numpy.add (ary1,ary2) numpy.subtract (ary1,ary2) numpy.multiply (ary1,ary2) numpy.divide (ary1,ary2) Trigonometric Functions: numpy.sin( ary * np.pi /180) numpy.cos( ary * np.pi /180) numpy.tan( ary * np.pi /180)

Expressing Conditional Logic The  numpy.where ()  function returns the indices of elements in an input array where the given condition is satisfied. numpy.where (condition[, x, y]) Here, x – yield True value y – yield False value

Methods for Boolean Array Boolean array is a type of array (collection of values) that can be used to represent logical ‘True’ or ‘False’ values stored. Declarations: boolAry = np.array ( objects,dtype = bool ) boolAry = condition using array Logical Methods: boolAry = np.logical_and (ary1,ary2) boolAry = np.logical_or (ary1,ary2) boolAry = np.logical_xor (ary1,ary2) boolAry = np.logical_not ( ary )

NumPy -Sorting numpy.sort () – Returns sorted copy of input array. numpy.sort ( ary , axis, kind, order) numpy.argsort () – Returns the indices that would sort an array. numpy.argsort ( a ,  axis=-1 ,  kind=None ,  order=None ) numpy.lexsort () - Perform an indirect stable sort using a sequence of keys. numpy.lexsort ( keys ,  axis=- 1 )

NumPy -Unique numpy.unique () - returns an array of unique elements in the input array. numpy.unique ( arr , return_index , return_inverse , return_counts )
Tags