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

numpy

NumPy is a fundamental package for numerical computations in Python, supporting N-dimensional array objects and various mathematical operations. It allows for the creation of arrays using functions like numpy.array, numpy.linspace, and numpy.arange, as well as operations such as addition and multiplication. NumPy is efficient in terms of storage and performance, enabling vectorized operations and faster execution compared to Python lists.

Uploaded by

piyush dwivedi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

numpy

NumPy is a fundamental package for numerical computations in Python, supporting N-dimensional array objects and various mathematical operations. It allows for the creation of arrays using functions like numpy.array, numpy.linspace, and numpy.arange, as well as operations such as addition and multiplication. NumPy is efficient in terms of storage and performance, enabling vectorized operations and faster execution compared to Python lists.

Uploaded by

piyush dwivedi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 23

NumPy

Introduction
• Stands for numerical python.
• Fundamental Package for numerical Computations.
• Supports N dimensional array objects that can be used for processing
multi-dimensional data.
• Supports different data types.
Introduction
• Using Numpy we can perform
• Mathematical and logical operations on arrays.
• Fourier Transform
• Linear Algebra Operations
• Random Number generations
Crate an array
• Array is the ordered collection of basic data types of given length
• Syntax: numpy.array(object)
Array
• Numpy can handle different categorical entries
Generate Array using linspace
• Return equaly spaced numbers within the given range.
• numpy.linspace(start, stop, num, dtype, retstep, dtype)
• Start : start of interval range
• Stop: The end value of the interval range
• Num: number of samples to be generated
• dtype: type of output array
• restep: return the samples, step value
Generate Array using linspace
• Generate an array b with start value 1 and stop value 5.
Generate array using np.arange
• np.arange returns equally spaced numbers within the given range
based on step size.
• Syntax: np.arange(start, stop, stepsize)
• Start : start of interval range
• Stop: The end value of the interval range
• Stepsize: stepsize in the interval
Generate array using np.arange
• Generate an array with start value = 1, stop value = 10 and stepsize =
2
Generate array using ones
• Numpy.ones returns an array of given shape and type filled with ones.
• Syntax: numpy.ones(shape, dtype)
• Shape: integer or sequence of integers
• Dtype: data type (default: float)
Generate array using zeros
• Numpy.zeros returns an array of given shape and type filled with
zeros.
• Syntax: numpy.zeros(shape, dtype)
• Shape: integer or sequence of integers
• Dtype: data type (default: float)
Generate array using random.rand()
• Numpy.random.rand() returns an array of given shape filled with
random values.
• Syntax: numpy.random.rand(shape)
Advantages of numpy
• Numpy supports vectorized operations.
• Array operations are carried out in c and hence universal functions in
numpy are faster than operations carried out in Python Lists.
Advanages of numpy: Consumes less storage
space
Reshape an array
• Recast an array to new shape without changing its data
Array Dimensions
• Shape Returns the dimensions of an array
Numpy addition
• Numpy.add() returns the element wise addition between two arrays.
Numpy Multiplication
• Numpy.multiply(): returns element wise multiplication between two
arrays.
Other numpy functions
Accessing Components of an array

• Components of an array can be accessed


using index number.

• Extract element 2 in array a : a(0,1)


Modifying an array using transpose
• Numpy.transpose(array): returns the transpose of an array.
Modify array using append
• Add the values at the end of array.
• Syntax: numpy.append(array,axis)

You might also like