Array with Python Numpy
About NumPy: Python NumPy Array is a module for Python. The name is an acronym for “Numeric Python” or “Numerical Python”. It is an extension module for Python, mostly written in C. It is a successor for two earlier computing Python libraries such as Numeric and numarray. It is the fundamental package for scientific computing. It is a general-purpose array-processing or manipulating python package. It provides a high-level performance on multidimensional array object and tools for working with these arrays. It is used for implementing multi-dimensional arrays and matrices.
Copyright @ 2019 Learntek. All Rights Reserved.
3
Sub Libraries include in NumPy: It contains basic linear algebra functions. It contains basic Fourier transforms. It contains a sophisticated random number of capabilities. It contains tools for integrating Fortran code and C/C++ code. It contains sophisticated random number capabilities
Copyright @ 2019 Learntek. All Rights Reserved.
4
Application of NumPy: Python NumPy Array is used in various applications such as Matrix Computations Numerical Analysis Image processing Signal processing Linear algebra A plethora of others
Copyright @ 2019 Learntek. All Rights Reserved.
5
Install NumPy Steps are as follows Step 1: Open command prompt Step 2: write pip install numpy
Copyright @ 2019 Learntek. All Rights Reserved.
6
Import NumPy with python Before we can use NumPy we will have to import it. >>> import numpy as it is complicated to write it every time we renamed it as np with the help of following the line of code >>> import numpy as np
Copyright @ 2019 Learntek. All Rights Reserved.
7
Numpy Array A numpy array is a collection of homogeneous values, all of the same data type, and is indexed by a tuple of nonnegative integers. The number of dimensions (means count of rows) is the rank of the array. The shape of an array is a tuple of integers giving the size of the array along each dimension. Python Training Online
Copyright @ 2019 Learntek. All Rights Reserved.
8
Creation of Numpy Array We can initialize it arrays from nested Python lists, and access elements using square brackets: Array can be crated with numpy.array #Creation of 1-D arry >>> import numpy as np >>> arr = np.array([8, 9, 10]) # Create a rank 1 array >>> print(arr) [ 8 9 10] >>> type(arr)
Copyright @ 2019 Learntek. All Rights Reserved.
9
Copyright @ 2019 Learntek. All Rights Reserved.
10
Array indexing It is used to access the particular element of the array >>> arr = np.array ( [8, 9, 10] ) >>> print ( arr[0] ) 8 >>> print ( arr[1] ) 9 >>> print ( arr[2] ) 10
Copyright @ 2019 Learntek. All Rights Reserved.
11
Copyright @ 2019 Learntek. All Rights Reserved.
12
To check the array dimension >>> arr.ndim 1 Shape of the Array You should check the shape of an array with the object shape preceded by the name of the array. >>> arr.shape >>> arr.shape (3,) >>> For a 1D array, the shape would be (n,) where n is the number of elements in your array. Copyright @ 2019 Learntek. All Rights Reserved.
13
Length of the array len ( ) method is used to find the length of the array >>> arr = np.array([8, 9, 10]) >>> print ( len ( arr ) ) 3
Copyright @ 2019 Learntek. All Rights Reserved.
14
Creation of 2-D arry >>> arr2d = np.array([[0, 1, 2], [3, 4, 5]]) # 2 x 3 array or create a rank of 2 >>> print (arr2d) [[0 1 2] [3 4 5]] >>> print (arr2d.ndim) 2 >>> print (arr2d.shape) (2, 3) For a 2D array, the shape would be (n,m) where n is the number of rows and m is the number of columns in your array. Copyright @ 2019 Learntek. All Rights Reserved.
15
Copyright @ 2019 Learntek. All Rights Reserved.
16
Indexing with 2-D array >>> arr2d = np.array([[0, 1, 2], [3, 4, 5]]) >>> print ( arr2d [0, 0] ) 0 >>> print ( arr2d [0, 1] ) 1 >>> print ( arr2d [1, 1] ) 4 >>> print ( arr2d [1, 2] ) 5 >>> Copyright @ 2019 Learntek. All Rights Reserved.
17
Copyright @ 2019 Learntek. All Rights Reserved.
18
Create an array of all zeros >>> arr2d = np.array([[0, 1, 2], [3, 4, 5]]) >>> print ( arr2d [0, 0] ) 0 >>> print ( arr2d [0, 1] ) 1 >>> print ( arr2d [1, 1] ) 4 >>> print ( arr2d [1, 2] ) 5 >>> If you want more info about NumPy Python, Just go through the link. https://www.learntek.org/blog/array-python-numpy/
Copyright @ 2019 Learntek. All Rights Reserved.
19
For more Training Information , Contact Us
Email : [email protected] USA : +1734 418 2465 INDIA : +40 4018 1306 +7799713624 Copyright @ 2018 Learntek. All Rights Reserved.
20