This document provides an introduction to NumPy arrays. It discusses arrays versus lists, how to create NumPy arrays using various functions like arange() and zeros(), and how to perform operations on NumPy arrays like arithmetic, mathematical functions, and manipulations. It also covers installing NumPy, importing it, and checking the version. NumPy arrays allow fast and efficient storage and manipulation of numerical data in Python.
NumPy is a Python package that provides multidimensional array and matrix objects as well as tools to work with these objects. It was created to handle large, multi-dimensional arrays and matrices efficiently. NumPy arrays enable fast operations on large datasets and facilitate scientific computing using Python. NumPy also contains functions for Fourier transforms, random number generation and linear algebra operations.
NumPy is a Python library that provides multidimensional array and matrix objects, along with tools to work with these objects. It is used for working with arrays and matrices, and has functions for linear algebra, Fourier transforms, and matrices. NumPy was created in 2005 and provides fast operations on arrays and matrices.
NumPy provides two fundamental objects for multi-dimensional arrays: the N-dimensional array object (ndarray) and the universal function object (ufunc). An ndarray is a homogeneous collection of items indexed using N integers. The shape and data type define an ndarray. NumPy arrays have a dtype attribute that returns the data type layout. Arrays can be created using the array() function and have various dimensions like 0D, 1D, 2D and 3D.
Essential numpy before you start your Machine Learning journey in python.pdfSmrati Kumar Katiyar
This document discusses various ways to create, access, and manipulate NumPy arrays. It covers creating arrays from lists, tuples, ranges, random data, identity matrices, and existing data. It also covers element-wise operations like addition, subtraction, multiplication and division. Other topics include checking array shape and datatype, matrix multiplication, representing vectors, matrices and tensors, broadcasting, and accessing elements through indexing, slicing, boolean and integer indexing.
NumPy is a Python library that provides multidimensional array and matrix objects to perform scientific computing. It contains efficient functions for operations on arrays like arithmetic, aggregation, copying, indexing, slicing, and reshaping. NumPy arrays have advantages over native Python sequences like fixed size and efficient mathematical operations. Common NumPy operations include elementwise arithmetic, aggregation functions, copying and transposing arrays, changing array shapes, and indexing/slicing arrays.
NumPy is a Python library that provides multidimensional arrays and matrices for numerical computing along with high-level mathematical functions to operate on these arrays. NumPy arrays can represent vectors, matrices, images, and tensors. NumPy allows fast numerical computing by taking advantage of optimized low-level C/C++ implementations and parallel computing on multicore processors. Common operations like element-wise array arithmetic and universal functions are much faster with NumPy than with native Python.
NumPy is a Python package that provides multidimensional array and matrix objects as well as tools to work with these objects. It was created to handle large, multi-dimensional arrays and matrices efficiently. NumPy arrays enable fast operations on large datasets and facilitate scientific computing using Python. NumPy also contains functions for Fourier transforms, random number generation and linear algebra operations.
NumPy is a Python library that provides multidimensional array and matrix objects, along with tools to work with these objects. It is used for working with arrays and matrices, and has functions for linear algebra, Fourier transforms, and matrices. NumPy was created in 2005 and provides fast operations on arrays and matrices.
NumPy provides two fundamental objects for multi-dimensional arrays: the N-dimensional array object (ndarray) and the universal function object (ufunc). An ndarray is a homogeneous collection of items indexed using N integers. The shape and data type define an ndarray. NumPy arrays have a dtype attribute that returns the data type layout. Arrays can be created using the array() function and have various dimensions like 0D, 1D, 2D and 3D.
Essential numpy before you start your Machine Learning journey in python.pdfSmrati Kumar Katiyar
This document discusses various ways to create, access, and manipulate NumPy arrays. It covers creating arrays from lists, tuples, ranges, random data, identity matrices, and existing data. It also covers element-wise operations like addition, subtraction, multiplication and division. Other topics include checking array shape and datatype, matrix multiplication, representing vectors, matrices and tensors, broadcasting, and accessing elements through indexing, slicing, boolean and integer indexing.
NumPy is a Python library that provides multidimensional array and matrix objects to perform scientific computing. It contains efficient functions for operations on arrays like arithmetic, aggregation, copying, indexing, slicing, and reshaping. NumPy arrays have advantages over native Python sequences like fixed size and efficient mathematical operations. Common NumPy operations include elementwise arithmetic, aggregation functions, copying and transposing arrays, changing array shapes, and indexing/slicing arrays.
NumPy is a Python library that provides multidimensional arrays and matrices for numerical computing along with high-level mathematical functions to operate on these arrays. NumPy arrays can represent vectors, matrices, images, and tensors. NumPy allows fast numerical computing by taking advantage of optimized low-level C/C++ implementations and parallel computing on multicore processors. Common operations like element-wise array arithmetic and universal functions are much faster with NumPy than with native Python.
This document provides an overview of arrays and operations on arrays using NumPy. It discusses creating arrays, mathematical operations on arrays like basic operations, squaring arrays, indexing and slicing arrays, and shape manipulation. Mathematical operations covered include conditional operations and matrix multiplication. Indexing and slicing cover selecting single elements, counting backwards with negative indexes, and combining positive and negative indexes. Shape manipulation discusses changing an array's shape, size, combining arrays, splitting arrays, and repeating arrays.
This document provides an overview of NumPy arrays, including how to create and manipulate vectors (1D arrays) and matrices (2D arrays). It discusses NumPy data types and shapes, and how to index, slice, and perform common operations on arrays like summation, multiplication, and dot products. It also compares the performance of vectorized NumPy operations versus equivalent Python for loops.
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.
NumPy is a numerical Python package that provides a multidimensional array object and tools to work with these arrays. It allows fast operations on arrays of numeric data and is used for scientific computing and mathematics. NumPy arrays can be initialized from nested Python lists and accessed using square brackets. Common operations include indexing, slicing, reshaping arrays, and performing mathematical operations element-wise or on whole arrays.
NumPy and Scipy provide MATLAB-like functionality for numerical computing in Python. NumPy features include typed multidimensional arrays for fast numerical computations like matrix math. NumPy is much faster than Python for tasks like matrix multiplication. NumPy arrays can represent vectors, matrices, images, tensors, and more. NumPy provides functions for creating, manipulating, and performing mathematical operations on arrays. Broadcasting rules allow arrays of different dimensions to perform element-wise operations.
This document provides an overview of the NumPy library in Python. It discusses what NumPy is, why arrays are needed, how to create arrays from existing data like lists and tuples, array attributes like size and shape, and basic array operations like addition and multiplication. It also introduces Pandas and the concepts of Series and DataFrames. Key points covered include that NumPy allows heterogeneous datatypes within arrays, different methods for creating arrays from data, and that arrays are more efficient than lists for numerical operations on large amounts of data.
NumPy is a Python library used for working with multidimensional arrays and matrices for scientific computing. It allows fast operations on arrays through optimized C code and is the foundation of the Python scientific computing stack. NumPy arrays can be created in many ways and support operations like indexing, slicing, broadcasting, and universal functions. NumPy provides many useful features for linear algebra, Fourier transforms, random number generation and more.
NumPy is a Python library used for working with multi-dimensional arrays and matrices for scientific computing. It allows fast operations on large data sets and arrays. NumPy arrays can be created from lists or ranges of values and support element-wise operations via universal functions. NumPy is the foundation of the Python scientific computing stack and provides key features like broadcasting for efficient computations.
This document provides an overview of NumPy arrays in 3 paragraphs. It begins by introducing NumPy as the core library for scientific computing in Python that consists of multidimensional array objects. The second paragraph describes one-dimensional and two-dimensional NumPy arrays, how to create them using functions like array(), and basic operations like slicing and joining arrays. The third paragraph covers various arithmetic operations that can be performed on one-dimensional and two-dimensional arrays like addition, subtraction, multiplication, and division.
NumPy is a Python library that provides multidimensional arrays and tools to work with these arrays. It contains sophisticated (optimized) functions for working with arrays and is commonly used in data science due to its speed and resource efficiency compared to regular Python lists. NumPy arrays store data in contiguous memory locations allowing for fast computations.
Data Analyzing And Visualization Using Python.pptxPoojaChavan51
This document discusses Python libraries for data analysis, specifically NumPy. It provides an overview of NumPy, describing it as a package for scientific computing and numerical processing. The document covers NumPy array structures, how to install NumPy, and how to import and create 1D arrays in NumPy using functions like array(), linspace(), and arange(). It also discusses different types of NumPy arrays like 1D, 2D, and n-dimensional arrays.
NumPy arrays can be created from Python lists by passing the list to the np.array() method. NumPy arrays differ from lists in that elements are stored contiguously in memory without comma separators. Multi-dimensional arrays can be created from nested lists. NumPy array attributes like shape and ndim provide information about array dimensions and elements. Individual elements can be accessed using indexes, and whole arrays or subsets of arrays can undergo vectorized operations for efficient processing.
This document provides an introduction to NumPy, the fundamental package for scientific computing with Python. It discusses what NumPy is, why it is useful compared to regular Python lists, how to define arrays of different dimensions, and how to initialize, manipulate, and perform operations on NumPy arrays. Some key capabilities of NumPy include N-dimensional arrays, broadcasting functions, integration with C/C++ and Fortran code, and tools for linear algebra and Fourier transforms.
Arrays are fundamental data structures that store elements of the same type. In Python, lists are used instead of arrays since there is no native array type. Lists can store elements of different types, making them more flexible than arrays. The NumPy package provides a multidimensional array object that allows high-performance operations and is used for scientific computing in Python. NumPy arrays have attributes like shape, size, type and support various operations like sum, min, max. Multidimensional arrays can be created in NumPy using functions like array, linspace, logspace, arange and initialized with zeros or ones.
The document provides information about getting started with iPython. It discusses how to install iPython, start iPython, use tab completion and help features. It also demonstrates basic math operations in iPython like addition, subtraction, multiplication, division and rounding numbers. The document then covers plotting graphs using iPython, embellishing plots, multiple plots and loading/plotting data from files. It also introduces key concepts in Python like lists, strings, files, arrays, conditionals, loops, tuples, dictionaries and sets. Finally, the document discusses functions and lambda functions in Python.
The document discusses NumPy, a package for scientific computing that provides tools for handling n-dimensional arrays. It describes NumPy's broadcasting rules which allow operations on arrays of different shapes, fancy indexing using arrays of indices, and indexing with boolean arrays. Broadcasting allows operations on arrays with incompatible shapes by expanding dimensions of size one. Fancy indexing extracts elements from an array using arrays of integer indices. Boolean indexing selects elements where a boolean mask is True.
This document contains a presentation by Abhijeet Anand on NumPy. It introduces NumPy as a Python library for working with arrays, which aims to provide array objects that are faster than traditional Python lists. NumPy arrays benefit from being stored continuously in memory, unlike lists. The presentation covers 1D, 2D and 3D arrays in NumPy and basic array properties and operations like shape, size, dtype, copying, sorting, addition, subtraction and more.
This document provides an overview of arrays and operations on arrays using NumPy. It discusses creating arrays, mathematical operations on arrays like basic operations, squaring arrays, indexing and slicing arrays, and shape manipulation. Mathematical operations covered include conditional operations and matrix multiplication. Indexing and slicing cover selecting single elements, counting backwards with negative indexes, and combining positive and negative indexes. Shape manipulation discusses changing an array's shape, size, combining arrays, splitting arrays, and repeating arrays.
This document provides an overview of NumPy arrays, including how to create and manipulate vectors (1D arrays) and matrices (2D arrays). It discusses NumPy data types and shapes, and how to index, slice, and perform common operations on arrays like summation, multiplication, and dot products. It also compares the performance of vectorized NumPy operations versus equivalent Python for loops.
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.
NumPy is a numerical Python package that provides a multidimensional array object and tools to work with these arrays. It allows fast operations on arrays of numeric data and is used for scientific computing and mathematics. NumPy arrays can be initialized from nested Python lists and accessed using square brackets. Common operations include indexing, slicing, reshaping arrays, and performing mathematical operations element-wise or on whole arrays.
NumPy and Scipy provide MATLAB-like functionality for numerical computing in Python. NumPy features include typed multidimensional arrays for fast numerical computations like matrix math. NumPy is much faster than Python for tasks like matrix multiplication. NumPy arrays can represent vectors, matrices, images, tensors, and more. NumPy provides functions for creating, manipulating, and performing mathematical operations on arrays. Broadcasting rules allow arrays of different dimensions to perform element-wise operations.
This document provides an overview of the NumPy library in Python. It discusses what NumPy is, why arrays are needed, how to create arrays from existing data like lists and tuples, array attributes like size and shape, and basic array operations like addition and multiplication. It also introduces Pandas and the concepts of Series and DataFrames. Key points covered include that NumPy allows heterogeneous datatypes within arrays, different methods for creating arrays from data, and that arrays are more efficient than lists for numerical operations on large amounts of data.
NumPy is a Python library used for working with multidimensional arrays and matrices for scientific computing. It allows fast operations on arrays through optimized C code and is the foundation of the Python scientific computing stack. NumPy arrays can be created in many ways and support operations like indexing, slicing, broadcasting, and universal functions. NumPy provides many useful features for linear algebra, Fourier transforms, random number generation and more.
NumPy is a Python library used for working with multi-dimensional arrays and matrices for scientific computing. It allows fast operations on large data sets and arrays. NumPy arrays can be created from lists or ranges of values and support element-wise operations via universal functions. NumPy is the foundation of the Python scientific computing stack and provides key features like broadcasting for efficient computations.
This document provides an overview of NumPy arrays in 3 paragraphs. It begins by introducing NumPy as the core library for scientific computing in Python that consists of multidimensional array objects. The second paragraph describes one-dimensional and two-dimensional NumPy arrays, how to create them using functions like array(), and basic operations like slicing and joining arrays. The third paragraph covers various arithmetic operations that can be performed on one-dimensional and two-dimensional arrays like addition, subtraction, multiplication, and division.
NumPy is a Python library that provides multidimensional arrays and tools to work with these arrays. It contains sophisticated (optimized) functions for working with arrays and is commonly used in data science due to its speed and resource efficiency compared to regular Python lists. NumPy arrays store data in contiguous memory locations allowing for fast computations.
Data Analyzing And Visualization Using Python.pptxPoojaChavan51
This document discusses Python libraries for data analysis, specifically NumPy. It provides an overview of NumPy, describing it as a package for scientific computing and numerical processing. The document covers NumPy array structures, how to install NumPy, and how to import and create 1D arrays in NumPy using functions like array(), linspace(), and arange(). It also discusses different types of NumPy arrays like 1D, 2D, and n-dimensional arrays.
NumPy arrays can be created from Python lists by passing the list to the np.array() method. NumPy arrays differ from lists in that elements are stored contiguously in memory without comma separators. Multi-dimensional arrays can be created from nested lists. NumPy array attributes like shape and ndim provide information about array dimensions and elements. Individual elements can be accessed using indexes, and whole arrays or subsets of arrays can undergo vectorized operations for efficient processing.
This document provides an introduction to NumPy, the fundamental package for scientific computing with Python. It discusses what NumPy is, why it is useful compared to regular Python lists, how to define arrays of different dimensions, and how to initialize, manipulate, and perform operations on NumPy arrays. Some key capabilities of NumPy include N-dimensional arrays, broadcasting functions, integration with C/C++ and Fortran code, and tools for linear algebra and Fourier transforms.
Arrays are fundamental data structures that store elements of the same type. In Python, lists are used instead of arrays since there is no native array type. Lists can store elements of different types, making them more flexible than arrays. The NumPy package provides a multidimensional array object that allows high-performance operations and is used for scientific computing in Python. NumPy arrays have attributes like shape, size, type and support various operations like sum, min, max. Multidimensional arrays can be created in NumPy using functions like array, linspace, logspace, arange and initialized with zeros or ones.
The document provides information about getting started with iPython. It discusses how to install iPython, start iPython, use tab completion and help features. It also demonstrates basic math operations in iPython like addition, subtraction, multiplication, division and rounding numbers. The document then covers plotting graphs using iPython, embellishing plots, multiple plots and loading/plotting data from files. It also introduces key concepts in Python like lists, strings, files, arrays, conditionals, loops, tuples, dictionaries and sets. Finally, the document discusses functions and lambda functions in Python.
The document discusses NumPy, a package for scientific computing that provides tools for handling n-dimensional arrays. It describes NumPy's broadcasting rules which allow operations on arrays of different shapes, fancy indexing using arrays of indices, and indexing with boolean arrays. Broadcasting allows operations on arrays with incompatible shapes by expanding dimensions of size one. Fancy indexing extracts elements from an array using arrays of integer indices. Boolean indexing selects elements where a boolean mask is True.
This document contains a presentation by Abhijeet Anand on NumPy. It introduces NumPy as a Python library for working with arrays, which aims to provide array objects that are faster than traditional Python lists. NumPy arrays benefit from being stored continuously in memory, unlike lists. The presentation covers 1D, 2D and 3D arrays in NumPy and basic array properties and operations like shape, size, dtype, copying, sorting, addition, subtraction and more.
How to Download & Install Module From the Odoo App Store in Odoo 17Celine George
Custom modules offer the flexibility to extend Odoo's capabilities, address unique requirements, and optimize workflows to align seamlessly with your organization's processes. By leveraging custom modules, businesses can unlock greater efficiency, productivity, and innovation, empowering them to stay competitive in today's dynamic market landscape. In this tutorial, we'll guide you step by step on how to easily download and install modules from the Odoo App Store.
How to Manage Reception Report in Odoo 17Celine George
A business may deal with both sales and purchases occasionally. They buy things from vendors and then sell them to their customers. Such dealings can be confusing at times. Because multiple clients may inquire about the same product at the same time, after purchasing those products, customers must be assigned to them. Odoo has a tool called Reception Report that can be used to complete this assignment. By enabling this, a reception report comes automatically after confirming a receipt, from which we can assign products to orders.
How Barcodes Can Be Leveraged Within Odoo 17Celine George
In this presentation, we will explore how barcodes can be leveraged within Odoo 17 to streamline our manufacturing processes. We will cover the configuration steps, how to utilize barcodes in different manufacturing scenarios, and the overall benefits of implementing this technology.
Level 3 NCEA - NZ: A Nation In the Making 1872 - 1900 SML.pptHenry Hollis
The History of NZ 1870-1900.
Making of a Nation.
From the NZ Wars to Liberals,
Richard Seddon, George Grey,
Social Laboratory, New Zealand,
Confiscations, Kotahitanga, Kingitanga, Parliament, Suffrage, Repudiation, Economic Change, Agriculture, Gold Mining, Timber, Flax, Sheep, Dairying,
Gender and Mental Health - Counselling and Family Therapy Applications and In...PsychoTech Services
A proprietary approach developed by bringing together the best of learning theories from Psychology, design principles from the world of visualization, and pedagogical methods from over a decade of training experience, that enables you to: Learn better, faster!
This presentation was provided by Racquel Jemison, Ph.D., Christina MacLaughlin, Ph.D., and Paulomi Majumder. Ph.D., all of the American Chemical Society, for the second session of NISO's 2024 Training Series "DEIA in the Scholarly Landscape." Session Two: 'Expanding Pathways to Publishing Careers,' was held June 13, 2024.
Elevate Your Nonprofit's Online Presence_ A Guide to Effective SEO Strategies...TechSoup
Whether you're new to SEO or looking to refine your existing strategies, this webinar will provide you with actionable insights and practical tips to elevate your nonprofit's online presence.
2. Introduction to NumPy
arrays vs lists,
array creation routines,
arrays from existing data,
indexing and slicing,
Operations on NumPy arrays,
array manipulation,
broadcasting,
binary operators,
NumPy functions: mathematical functions, statistical
functions, sort, search and counting functions
3. arrays vs lists
• An array is also a data structure that stores a
collection of items. Like lists, arrays are ordered,
mutable, enclosed in square brackets, and able to
store non-unique items.
• A list in Python is a collection of items which can
contain elements of multiple data types.
• A array in Python is a collection of items which can
contain elements of same data types
• The Python array module requires all array
elements to be of the same type.
• On the other hand, NumPy arrays support different
data types.
4. • NumPy stands for Numerical Python
• NumPy is a Python library used for working with arrays.
• 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.
• The array object in NumPy is called ndarray, it provides a lot
of supporting functions
7. Installation of NumPy
!pip install numpy
Once NumPy is installed, import it in your applications by adding
the import keyword:
import numpy
Create an alias with the as keyword while importing:
import numpy as np
Checking NumPy Version
The version string is stored under __version__ attribute
import numpy as np
print(np.__version__)
8. What are Modules in Python?
In python a module means a saved python file. This file can
contain a group of classes, methods, functions and variables.
What is import keyword in python?
If we want to use other members(variable, function, etc) of a
module in your program, then you should import that module by
using the import keyword. After importing you can access
members by using the name of that module.
from keyword in python:
We can import some specific members of the module
by using the from keyword. The main advantage of the
from keyword is we can access members directly
without using module names.
9.
10.
11. N-Dimensional array(ndarray) in Numpy
NumPy is used to work with arrays.
The array object in NumPy is called ndarray.
We can create a NumPy ndarray object by using the array()
function.
To create an ndarray, we can pass a list, tuple or any array-like
object into the array() method, and it will be converted into
an ndarray
12. Create a 1-D array containing the values
0,1,2,3,4,5:
In numpy dimensions are called rank or axes.
Size of the array along each dimension is known as shape of
the array
13.
14.
15.
16.
17. Cont..
An array can have any number of dimensions.
When the array is created, you can define the
number of dimensions by using the ndmin argument.
18. There are various ways to create arrays in
NumPy:
• You can create an array from a regular Python
list or tuple using the array function.
• Functions to create arrays:
Using arange() function to create a Numpy
array.
19. Using arange() function to create a Numpy array:
arange(start, end, step)
Example:
arange_array = np.arange(0,11,2)
print(arange_array)
21. Reshaping arrays
Reshaping means changing the shape of an array.
The shape of an array is the number of elements in each
dimension.
By reshaping we can add or remove dimensions or change
number of elements in each dimension.
22. array creation routines
The ndarray object can be constructed by using
the following routines:
Numpy.empty
The empty routine is used to create an
uninitialized array of specified shape and data
type.
The syntax is given below.
numpy.empty(shape, dtype = data_type)
24. NumPy.Zeros
This routine is used to create the numpy array
with the specified shape where each numpy
array item is initialized to 0.
import numpy as np
arr = np.zeros((3,2), dtype = int)
print(arr)
25.
26. NumPy.ones
This routine is used to create the numpy array
with the specified shape where each numpy
array item is initialized to 1.
import numpy as np
arr = np.ones((3,2), dtype = int)
print(arr)
27.
28. Array From Existing Data
numpy.asarray()
Difference array() and asarray() function:
The main difference is that when you try to make a
numpy array using np.array, it would create a copy of
the object array and not reflect changes to the original
array. On the other hand, when you use numpy asarray,
it would reflect changes to the original array.
31. bitwise_and
import numpy as np
a = 10
b = 12
print("binary representation of a:",bin(a))
print("binary representation of b:",bin(b))
print("Bitwise and of a and b: ",np.bitwise_and(a,b))
32. If both side bit is on result will be On
a b a & b
0 0 0
0 1 0
1 0 0
1 1 1
33. Steps to solve:-
• a = 12 (find binary form:1100 )
• b = 25 (find binary form:11001)
How to find Binary:
64 32 16 8 4 2 1
0 1 1 0 0
1 1 0 0 1
12
25
8
1 0 0 0
34. bitwise_or Operator
import numpy as np
a = 50
b = 90
print("binary representation of a:",bin(a))
print("binary representation of b:",bin(b))
print("Bitwise-or of a and b: ",np.bitwise_or(a,b))
35. If any side bit is on result will be On
a b a | b
0 0 0
0 1 1
1 0 1
1 1 1
36. Steps to solve:-
• a = 12 (find binary form:1100 )
• b = 25 (find binary form:11001)
How to find Binary:
64 32 16 8 4 2 1
0 1 1 0 0
1 1 0 0 1
12
25
29
1 1 1 0 1
44. numpy.char.center()
This function returns an array of the required
width so that the input string is centered and
padded on the left and right with fillchar.
import numpy as np
# np.char.center(arr, width,fillchar)
print (np.char.center('hello', 20,fillchar = '*’))
46. Operations on NumPy arrays
You can perform arithmetic directly on NumPy
arrays, such as addition and subtraction.
For example, two arrays can be added
together to create a new array where the
values at each index are added together.
47. import numpy as np
a = np.array([1, 2, 3])
b = np.array([1, 1, 1])
c = a + b
print(c)
A. [1,2,3,1,1,1]
B. [1,1,1,1,2,3]
C. [2,3,4]
D. None
48. import numpy as np
a = np.array([1, 2, 3])
b = np.array([1, 1, 1])
c = a + b
print(c)
a = [1, 2, 3]
b = [1, 1, 1]
c = a + b
c = [1 + 1, 2 + 1, 3 + 1]
49. Limitation with Array Arithmetic
Arithmetic may only be performed on arrays
that have the same dimensions and
dimensions with the same size.
Arrays with different sizes cannot be added,
subtracted, or generally be used in arithmetic.
A way to overcome this use array broadcasting
and is available in NumPy
50. arithmetic operations
For performing arithmetic operations such as add(), subtract(), multiply(), and
divide() must be of the same shape.
import numpy as np
a = np.array([10,20,30])
b = np.array([1,2,3])
print(a.shape)
print(b.shape)
print(np.add(a,b))
print(np.subtract(a,b))
print(np.multiply(a,b))
print(np.divide(a,b))
52. You can perform arithmetic operations with
different dimension using broadcasting rule :
Main rule:
• Size of each dimension should be same
• Size of one of the dimension should be 1.
53. array broadcasting rule
Rule1: If the two arrays differ in their number of
dimensions, the shape of the one with fewer
dimensions is padded with ones on its leading (left)
side.
Rule2: If the shape of the two arrays does not match in
any dimension, the array with shape equal to 1 in that
dimension is stretched to match the other shape.
Rule3: If in any dimension the sizes disagree and
neither is equal to 1, an error is raised.
54. import numpy as np
a1=np.array([10,20,30])
b1=np.array([1,2,3,4])
print(a1+b1)
a1=[10,20,30]
shape:3
dimension:1D
b1=[1,2,3,4]
shape:4
dimension:1D
Rule1: not satisfied
Rule2:not satisfied
Check with
example:
55. Check with another example2
import numpy as np
a1=np.array([[1,2],[3,4],[5,6]])
b1=np.array([10,20])
print(a1+b1)
a1:
Shape: 3,2
Dimension:2D
b1:
Shape:2
Dimension:1D
56.
57. Check with another example3
import numpy as np
a1=np.array([[1,2],[3,4],[5,6]])
b1=np.array([10,20,30])
print(a1+b1)
a1:
Shape: 3,2
Dimension:2D
b1:
Shape:3
Dimension:1D
58.
59. Check with another example4
import numpy as np
a1=np.array([[1,2],[3,4],[5,6]])
b1=np.array([[10,20],[30,40]])
print(a1+b1)
a1:
Shape: 3,2
Dimension:2D
b1:
Shape:2,2
Dimension:2D
62. 1. Arithmetic Functions
NumPy Add function
add()
This function is used to add two arrays. If we
add arrays having dissimilar shapes we get
“Value Error”.
NumPy Subtract function
subtract()
We use this function to output the difference of
two arrays. If we subtract two arrays having
63. 1. Arithmetic Functions
NumPy Multiply function
multiply()
We use this function to output the
multiplication of two arrays. We cannot work
with dissimilar arrays.
NumPy Divide Function
divide()
We use this function to output the division of
two arrays. We cannot divide dissimilar arrays.
64. 1. Arithmetic Functions
NumPy Mod and Remainder function:
mod()
remainder()
We use both the functions to output the
remainder of the division of two arrays.
65. 2. Trigonometric Functions
np.sin()- It performs trigonometric sine calculation
element-wise.
np.cos()- It performs trigonometric cosine
calculation element-wise.
np.tan()- It performs trigonometric tangent
calculation element-wise.
np.arcsin()- It performs trigonometric inverse sine
element-wise.
np.arccos()- It performs trigonometric inverse of
cosine element-wise.
np.arctan()- It performs trigonometric inverse of
tangent element-wise.
66. Real life applications of trigonometry
Trigonometry can be used to measure the height
of a building or mountains.
if you know the distance from where you observe the
building and the angle of elevation you can easily find
the height of the building.
67. Problem statement
A man standing at a certain distance from a building,
observe the angle of elevation of its top to be 60∘. He
walks 30 yds away from the building. Now, the angle of
elevation of the building’s top is 30∘. How high is the
building?
77. Exponential and Logarithmic Functions
np.exp()- This function calculates the exponential of
the input array elements.
np.log()- This function calculates the natural log of the
input array elements. Natural Logarithm of a value is
the inverse of its exponential value.
78. Exponential and Logarithmic Functions
John Napier
John Napier is best known as the discoverer of
logarithms in 1614
79. In mathematics, the logarithm is the inverse
function to exponentiation.
Exponentiation is a mathematical operation,
written as bn, involving two numbers, the base b
and the exponent or power n, and pronounced
as "b (raised) to the (power of) n". When n is a
positive integer, exponentiation corresponds to
repeated multiplication of the base.
81. Logarithmic function is of the form
f(x) = logax
or,
y = logax,
where a > 0 and a!=1
x we can take (0 to ∞)
based on x value y value will be have range(- ∞ to ∞)
It is the inverse of the exponential function ay = x
82. Real life examples:
Suppose these values indicating salary, distance from earth to sun and
Molecules. You want to plot the graph for these values
83. If we will plot graph like this:
No’s will be seems like very closer, we can solve this using logarithmic
84.
85. The Richter scale is a base-10 logarithmic scale, meaning that each order of
magnitude is 10 times more intensive than the last one.
86. Rounding Functions
np.around()- This function is used to round off a decimal number
to desired number of positions. The function takes two
parameters: the input number and the precision of decimal
places.
np.floor()- This function returns the floor value of the input
decimal value. Floor value is the largest integer number less than
the input value.
87. Sort, Search & Counting Functions
There are various sorting algorithms like quicksort, merge sort
and heapsort which is implemented using the numpy.sort()
function.
Syntax:
numpy.sort(input, axis, kind, order)
input: It represents the input array which is to be sorted.
axis: It represents the axis along which the array is to be sorted.
If the axis is not mentioned, then the sorting is done along the
last available axis.
kind: It represents the type of sorting algorithm which is to be
used while sorting. The default is quick sort.
order: It represents the filed according to which the array is to be
sorted in the case if the array contains the fields.