[go: up one dir, main page]

0% found this document useful (0 votes)
106 views14 pages

Jyoti Shukla (SME)

The document discusses NumPy, an open-source Python library for working with multidimensional arrays and matrices. It introduces NumPy arrays, their advantages over regular Python lists, and their dimensions. It also covers initializing arrays, properties of arrays like shape and size, copying arrays, sorting arrays, and common mathematical operations on arrays like addition, subtraction, multiplication and more.

Uploaded by

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

Jyoti Shukla (SME)

The document discusses NumPy, an open-source Python library for working with multidimensional arrays and matrices. It introduces NumPy arrays, their advantages over regular Python lists, and their dimensions. It also covers initializing arrays, properties of arrays like shape and size, copying arrays, sorting arrays, and common mathematical operations on arrays like addition, subtraction, multiplication and more.

Uploaded by

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

-Jyoti Shukla(SME)

Topics
 Introduction of Numpy
 Indexing & slicing
 Mathematical computation
 Array comparison
 array Manipulation
 transpose & swapcase
 insert and remove
Topics
 What is Numpy?
 Why Numpy?
 What is Array?
 Dimensions in Arrays
 Initialization of an Array.
What is Numerical Python?
 NumPy is the fundamental package for scientific
computing with Python.
 A powerful N-dimensional array object
 Sophisticated (broadcasting) functions
 Tools for integrating C/C++ and Fortran code
 Useful linear algebra, Fourier transform, and random
number capabilities
Why NumPy?
 NumPy arrays are stored at one continuous place in
memory unlike lists, so processes can access and
manipulate them very efficiently. This behavior is
called locality of reference in computer science.
 This is the main reason why Numpy is faster than lists.
Also it is optimized to work with latest CPU
architectures.
Arrays
 NumPy’s main object is the homogeneous
multidimensional array.
 It is a table of elements (usually numbers), all of the
same type, indexed by a tuple of positive integers.
 In NumPy dimensions are called axes. The number of
axes is rank.
 NumPy’s array class is called ndarray. It is also known
by the alias array.
Dimensions in Arrays

 A dimension in arrays is one level of array depth


1-D Arrays
 An array that has 0-D arrays as its elements is called
uni-dimensional or 1-D array.These are the most
common and basic arrays.
 import numpy as np
arr = np.array([1, 2, 3, 4, 5])
print(arr)
2-D Arrays
 An array that has 1-D arrays as its elements is called a
2-D array.These are often used to represent matrix or
2nd order tensors.
 import numpy as np
arr = np.array([[1, 2, 3], [4, 5, 6]])
print(arr)
3-D arrays
 An array that has 2-D arrays (matrices) as its elements
is called 3-D array.These are often used to represent a
3rd order tensor.
 import numpy as np
arr = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 2, 3], [4, 5, 6]]])
print(arr)
INITIALIZTION
np.array([1,2,3]) 1d array

np.array([(1,2,3),(4,5,6)]) 2d array

np.arange(start,stop,step) range array

Add evenly spaced values btw interval to array of


np.linspace(0,2,9)
length

np.zeros((1,2)) Create and array filled with zeros

np.ones((1,2)) Creates an array filled with ones

np.random.random((5,5)) Creates random array

np.empty((2,2)) Creates an empty array


ARRAY PROPERTIES

Syntax Description

array.shape Dimensions (Rows,Columns)

len(array) Length of Array

array.ndim Number of Array Dimensions

array.size Number of Array Elements

array.dtype Data Type

type(array) Type of Array


COPYING/SORTING

np.copy(array) Creates copy of array

array.sort() Sorts an array

array.sort(axis=0) Sorts axis of array


Operations
Operator Description

np.add(x,y)
Addition
x + y

np.substract(x,y)
Subtraction
x – y

np.divide(x,y)
Division
x / y

np.multiply(x,y)
Multiplication
x @ y

np.sqrt(x) Square Root

np.sin(x) Element-wise sine

np.cos(x) Element-wise cosine

np.log(x) Element-wise natural log

np.dot(x,y) Dot product

np.roots([1,0,-4]) Roots of a given polynomial coefficients

You might also like