0% found this document useful (0 votes)
4 views6 pages

NumPy Basics and Functions Tutorial

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)
4 views6 pages

NumPy Basics and Functions Tutorial

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

NumPy

About the Tutorial


NumPy, which stands for Numerical Python, is a library consisting of multidimensional
array objects and a collection of routines for processing those arrays. Using NumPy,
mathematical and logical operations on arrays can be performed.

This tutorial explains the basics of NumPy such as its architecture and environment. It also
discusses the various array functions, types of indexing, etc. An introduction to Matplotlib
is also provided. All this is explained with the help of examples for better understanding.

Audience
This tutorial has been prepared for those who want to learn about the basics and various
functions of NumPy. It is specifically useful for algorithm developers. After completing this
tutorial, you will find yourself at a moderate level of expertise from where you can take
yourself to higher levels of expertise.

Prerequisites
You should have a basic understanding of computer programming terminologies. A basic
understanding of Python and any of the programming languages is a plus.

Disclaimer & Copyright


 Copyright 2016 by Tutorials Point (I) Pvt. Ltd.

All the content and graphics published in this e-book are the property of Tutorials Point (I)
Pvt. Ltd. The user of this e-book is prohibited to reuse, retain, copy, distribute or republish
any contents or a part of contents of this e-book in any manner without written consent
of the publisher.

We strive to update the contents of our website and tutorials as timely and as precisely as
possible, however, the contents may contain inaccuracies or errors. Tutorials Point (I) Pvt.
Ltd. provides no guarantee regarding the accuracy, timeliness or completeness of our
website or its contents including this tutorial. If you discover any errors on our website or
in this tutorial, please notify us at contact@[Link].

i
NumPy

Table of Contents
About the Tutorial .................................................................................................................................... i

Audience .................................................................................................................................................. i

Prerequisites ............................................................................................................................................ i

Disclaimer & Copyright............................................................................................................................. i

Table of Contents .................................................................................................................................... ii

1. NUMPY − INTRODUCTION ................................................................................................... 1

2. NUMPY − ENVIRONMENT .................................................................................................... 2

3. NUMPY − NDARRAY OBJECT ................................................................................................ 4

4. NUMPY − DATA TYPES ......................................................................................................... 7

Data Type Objects (dtype) ....................................................................................................................... 8

5. NUMPY − ARRAY ATTRIBUTES............................................................................................ 12

[Link] ....................................................................................................................................... 12

[Link] ........................................................................................................................................ 13

[Link] ..................................................................................................................................... 14

[Link] .......................................................................................................................................... 14

6. NUMPY − ARRAY CREATION ROUTINES ............................................................................. 16

[Link]........................................................................................................................................ 16

[Link] ......................................................................................................................................... 17

[Link] .......................................................................................................................................... 18

7. NUMPY − ARRAY FROM EXISTING DATA ............................................................................ 19

[Link] ...................................................................................................................................... 19

[Link] ................................................................................................................................ 20

ii
NumPy

[Link]..................................................................................................................................... 21

8. NUMPY − ARRAY FROM NUMERICAL RANGES ................................................................... 23

[Link] ....................................................................................................................................... 23

[Link] ..................................................................................................................................... 24

[Link] .................................................................................................................................... 25

9. NUMPY − INDEXING & SLICING.......................................................................................... 27

10. NUMPY − ADVANCED INDEXING........................................................................................ 31

Integer Indexing .................................................................................................................................... 31

Boolean Array Indexing ......................................................................................................................... 33

11. NUMPY − BROADCASTING ................................................................................................. 35

12. NUMPY − ITERATING OVER ARRAY .................................................................................... 38

Iteration Order ...................................................................................................................................... 39

Modifying Array Values ......................................................................................................................... 42

External Loop ........................................................................................................................................ 42

Broadcasting Iteration ........................................................................................................................... 43

13. NUMPY – ARRAY MANIPULATION...................................................................................... 45

[Link] ..................................................................................................................................... 47

[Link] ............................................................................................................................... 48

[Link] .......................................................................................................................... 48

[Link] .......................................................................................................................................... 49

[Link] .................................................................................................................................. 50

[Link].T................................................................................................................................... 51

[Link] .................................................................................................................................. 52

[Link] ...................................................................................................................................... 53

[Link] .................................................................................................................................. 54

iii
NumPy

numpy.broadcast_to ............................................................................................................................. 56

numpy.expand_dims ............................................................................................................................. 57

[Link] ..................................................................................................................................... 59

[Link] .............................................................................................................................. 60

[Link] .......................................................................................................................................... 61

[Link] and [Link] .......................................................................................................... 63

[Link] ........................................................................................................................................... 64

[Link] and [Link] ............................................................................................................. 65

[Link] ......................................................................................................................................... 66

[Link] ...................................................................................................................................... 68

[Link] ......................................................................................................................................... 69

[Link] ........................................................................................................................................ 71

[Link] ....................................................................................................................................... 72

14. NUMPY – BINARY OPERATORS .......................................................................................... 75

bitwise_and .......................................................................................................................................... 75

bitwise_or ............................................................................................................................................. 76

[Link]() ...................................................................................................................................... 77

left_shift ............................................................................................................................................... 78

right_shift ............................................................................................................................................. 79

15. NUMPY − STRING FUNCTIONS ........................................................................................... 80

16. NUMPY − MATHEMATICAL FUNCTIONS ............................................................................ 85

Trigonometric Functions ....................................................................................................................... 85

Functions for Rounding ......................................................................................................................... 88

17. NUMPY − ARITHMETIC OPERATIONS ................................................................................. 91

[Link]() ................................................................................................................................ 93

iv
NumPy

[Link]() ..................................................................................................................................... 94

[Link]() ........................................................................................................................................ 95

18. NUMPY − STATISTICAL FUNCTIONS ................................................................................... 98

[Link]() and [Link]() ......................................................................................................... 98

[Link]() .......................................................................................................................................... 99

[Link]() ............................................................................................................................. 100

[Link]().................................................................................................................................. 102

[Link]() .................................................................................................................................... 103

[Link]() ................................................................................................................................. 104

Standard Deviation ............................................................................................................................. 106

Variance .............................................................................................................................................. 106

19. NUMPY − SORT, SEARCH & COUNTING FUNCTIONS ........................................................ 107

[Link]() ....................................................................................................................................... 107

[Link]() .................................................................................................................................. 109

[Link]()................................................................................................................................... 110

[Link]() and [Link]() ................................................................................................. 110

[Link]() ................................................................................................................................ 112

[Link]() ................................................................................................................................... 113

[Link]() .................................................................................................................................. 114

20. NUMPY − BYTE SWAPPING .............................................................................................. 116

[Link]() ................................................................................................................. 116

21. NUMPY − COPIES & VIEWS .............................................................................................. 117

No Copy .............................................................................................................................................. 117

View or Shallow Copy.......................................................................................................................... 118

Deep Copy ........................................................................................................................................... 120

You might also like