Numpy For Data Science - Real Time Experience

所在平台: Udemy

课程主页: https://www.udemy.com/course/python-numpy-exercises/

课程评论:没有评论

第一个写评论        关注课程

课程简介

本课程是关于使用 Python 编程语言中的 NumPy 库进行数值计算的综合指南。课程通过 Jupyter Notebook 中的实时编码练习,深入讲解 NumPy 的功能,旨在帮助学员掌握该库以进行高效的数值计算。 **课程要点包括:** * **NumPy 数组基础:** NumPy 数组是 Python 中进行数值计算的核心,提供比内置列表和元组更高性能的替代方案。 * **数组创建:** * 从列表、元组创建一维、二维、三维数组。 * 使用 `np.asarray()` 转换数据类型。 * 使用 `np.arange()` 创建数字序列。 * 指定数组的维度和数据类型,例如 `np.array([1,2,3,4], ndmin = 2, dtype = complex)`。 * **数组属性:** * `ndim`:查看数组的维度(轴数/秩)。 * `shape`:查看数组的形状(矩阵、行、列)。 * `size`:查看数组的总元素数量。 * `dtype`:查看数组元素的数据类型。 * `itemsize`:查看每个元素的大小(以字节为单位)。 * `type()`:查看数组的类型。 * `.data`:获取数组第一个字节的内存地址。 * `strides`:查看内存中跳过多少字节才能访问下一个元素。 * **数组操作:** * 数组的加、减、乘、除运算,也可以使用 `np.add()`, `np.subtract()`, `np.multiply()`, `np.divide()` 等函数。 * **特殊数组创建:** * `np.zeros()`:创建全零数组。 * `np.ones()`:创建全一数组。 * `np.full()`:创建填充常数值的数组。 * `np.random` 模块:用于生成随机数的函数,包括 `random()`、`randint()`、`rand()`、`randn()`、`uniform()`、`choice()`、`normal()`。 * `np.linspace()`:在给定区间内返回等间距的数值。 * `np.empty()`:创建具有任意值的数组,不初始化。 * `np.eye()`:创建对角线为 1,其余为 0 的二维数组。 * `np.identity()`:创建单位矩阵(方阵)。 * `np.ones_like()`:创建与给定数组形状和类型相同的全一数组。 * `np.zeros_like()`:创建与给定数组形状和类型相同的全零数组。 * `np.full_like()`:创建与给定数组形状和类型相同的常数值填充数组。 * **重塑与变换:** * `reshape()`:重塑数组形状。 * `flatten()`:将数组展平成一维。 * `transpose()`:转置数组。 * `ravel()`:返回数组的视图(如果可能),展平成一维。 * **索引与切片:** * 使用方括号 `[]`进行索引和切片。 * 使用冒号 `:` 进行切片。 * 使用布尔值进行索引。 * **数学函数:** * `np.sqrt()`:平方根。 * `np.exp()`:指数函数。 * `np.log()`:自然对数。 * `np.sin()`, `np.cos()`, `np.tan()`:三角函数。 * **统计函数:** * `sum()`、`std()`、`var()`、`mean()`、`max()`、`min()`:计算总和、标准差、方差、均值、最大值、最小值。 * **通用函数 (ufuncs):** * `np.add()`, `np.subtract()`, `np.multiply()`, `np.divide()` 等,用于执行元素级计算。 * **其他重要函数:** * `np.diag()`:提取或构建对角线。 * `np.sort()`:对数组进行排序。 * `np.concatenate()`:连接数组。 * `np.vstack()`、`np.hstack()`:垂直和水平堆叠数组。 * `np.split()`、`np.hsplit()`:分割数组。 * `np.copy()`:浅拷贝和深拷贝。 * `np.where()`:根据条件选择元素。 * `np.dot()`:计算点积。 * `np.any()`:检查是否任何元素满足条件。 * `np.all()`:检查是否所有元素都满足条件。 * 数组内元素替换。 * 多维数组的复杂索引。 本课程旨在为初学者和有经验的 Python 程序员提供实践经验,以增强他们在数值计算方面的技能。

课程评论(0条)

课程详情

Welcome to the comprehensive guide to mastering Numerical Python, also known as Numpy. In this course, we dive deep into the Numpy library within the Python Programming Language, offering real-time coding exercises in Jupyter Notebook. Our aim is to demystify Numpy's functionality and empower you with the ability to leverage its power for efficient numerical computations.Numpy arrays are the cornerstone of numerical computing in Python. They provide a high-performance alternative to Python's built-in lists and tuples, enabling lightning-fast mathematical operations. Throughout this course, you'll explore a plethora of Numpy commands, equipping you with the skills to tackle a wide range of numerical tasks effortlessly.Let's embark on this journey to unlock the full potential of Numpy and revolutionize your approach to numerical computations. Whether you're a beginner or an experienced Python programmer, this course offers valuable insights and practical exercises to elevate your proficiency in numerical computing.Some Numpy Commands that we will use in this course.1. Import numpy as np2. 1-D Array - A = np.array( [1,2,3,4,5] ) # To create a One-dimensional array.3. 2-D Array - A = np.array( [[1,2,3],[4,5,6]] ) # To create a Two-dimensional array.4. 3-D Array - A = np.array( [[[1,2,3],[4,5,6],[7,8,9]]] ) # To create a Three-dimensional array.5. Array From List - L = np.array( [1,2,3,4,5] ) # To create an array from list.6. Array From Tuple - T = np.array( (11,22,33,44,55) ) # To create an array from tuple.7. np.asarray( ) - To convert any datatype (list,tuple) into numpy array.Ex: L_Array = np.asarray(list) ; T_Array = np.asarray(tuple)8. Dynamic Array - A dynamic array is similar to an array, but with the difference that its size can be dynamically modified at runtime.9. np.array( [1,2,3,4] , ndmin = 2 , dtype = complex ) # We can set the dimension and datatype of any array.10. np.arange() - A = np.arange( 1,20,3 ) # To create sequences of numbers.11. Reshape () - A = A.reshape ( 3,4 ) # To reshape an array.12. Ndim - A.ndim # To show the number of axis (dimensions/rank) of the array.13. shape - A.shape # Shape of the array i.e., matrix, rows, columns.14. Size - A.size # It shows the total no. of elements of the array.15. dtype - A.dtype # It shows the data type of elements of the array.16. itemsize - A.itemsize # It shows the size in bytes of each element of the array.17. type() - type(A) # It shows the type of the array.18..data - # It indicates the memory address of the first byte in the array.19. strides - A.strides # It is the no. of bytes that should be skipped in memory to go to the next element.20. A = np.array( [[1,2,3], [4,5,6]] , dtype = float ) # Creating an array from lists with type float.21. Arrays Operations - A = np.array([1,2,3,4]) , B = np.array([11,22,33,44])A + B à [ 12 24 36 48 ] ;; B - A à [ 10 20 30 40 ] ;; A * B à [ 11 44 99 176 ] ;; B / A à [ 11. 11. 11. 11. ] , OR ,np.add(A,B) à [ 12 24 36 48 ] ;; np.subtract(B,A) à [ 10 20 30 40 ] ;; np.multiply(A,B) à [ 11 44 99 176 ] ;; np.divide(B,A) à [ 11. 11. 11. 11. ]22. Zeros Array - An array in which all values are 0- ZA = np.zeros( (3,4) , dtype = int/float/str ) # Creating an array of all zeros values of given shape and type.- We can define the shape and data-type of zeros array.- We can create 1-D, 2-D, as well 3-D zeros array.- The default data-type is float.23. Ones Array - An array in which all values are 1- A = np.ones( (4,3) , dtype = int/float/str ) # Creating an array of all ones values of given shape and type.- We can define the shape and data-type of ones array.- We can create 1-D, 2-D, as well 3-D ones array.- The default data-type is float.24. Full Value Array - An array in which all values are same (constant)- A = np.full ( (3,4), 7 ) # Creating an array of 3x4 with one constant value (7) everywhere.- We can define the shape, and pass the value to be filled in the 'Full Arrays'.- We can create 1-D, 2-D, as well as 3-D Full Array, with integer, float or string values.- The default data-type is Integer.25. Random module - This module contains the functions which are used for generating random numbers.A. Random Function - It returns random float number(s) between 0 and 1.np.random.random((2,3)) # It creates a 2-D array of shape 2x3 with random values.B. Randint Function- It generates random integer number(s) between given range.- By default, the range starts from 0.- The numbers can repeat.np.random.randint(5,20,4) # It create a 1-D array of given no. of integer values (4 here) between given input numbers 5 & 20. The values can repeat.np.random.randint(5,20,(4,3)) # It creates a 2-D array of shape 4x3, between given input numbers 5 & 20. The values can repeat.C. Rand Function - It returns random float number(s) between 0 and 1.np.random.rand(10) # It creates an array of 10 random numbers between 0 and 1.D. Randn Function - It returns random float numbers (positive and negative both) in the form of array.np.random.randn(2,3,4) # It displays values (+/-) in the form of arrays.E. Uniform Function- It returns random float number(s) between the given range of values.- The random numbers can't repeat.- By default, the range starts from 0.- If nothing is passed in (), it will return a float number between 0 and 1.np.random.uniform(1,5,50) # It displays given no. of unique values between given input numbers. The values can't repeat. The values are in float format.F. Choice Function- It returns random integer number(s) from the given sequence.- The range starts from 0 by default.- If only 1 element is passed, then it will return a number between 0 and that element.- By default, replace = True , which means the numbers can repeat.np.random.choice( [2,5,8,9,1,7] , size=16 , replace=True/False) # To create an array with 16 elements from the given list of numbers ; replace = True means elements can repeatnp.random.normal( loc=100, scale=5 , size=10 ) # It draws a random sample from normal distribution ;loc - mean of distribution ; scale -std dev of distribution ; size - no. of elements.26. Linspace Function - np.linspace() - It returns evenly(linearly) spaced values within a given interval.np.linspace(start, stop , num=50, endpoint=True, retstep=True, dtype=None) ;Ex - A = np.linspace(2, 20, num=15) ; B = np.linspace (1,100,12)27. Flatten Array - A.flatten() # It is used to get a copy of array collapsed into 1-D.28. Empty Function - np.empty() - # Empty Function is used to create an array of arbitrary values, of given shape and datatype, without initializing the entries.A = np.empty( 4 ) ;; B = np.empty( (5,3) , dtype=int ) ;; C = np.empty( [2,5,3] , dtype=object )Syntax: np.empty ( shape, dtype )- Shape can given in list or tuple form- The default datatype is float29. We can define the data types of rows & columnsA = np.full( (2,3), 3, dtype = [ (‘x',float) , (‘y',int) ])30. Eye Function - np.eye() - The Eye Function returns a 2-D array , with 1 on diagonal and 0 elsewhere.Syntax: np.eye(shape, k, dtype)- Here, if only No. of Rows is passed, then No. of Columns = No. of Rows- K is Index of diagonal, by default, k=0 means Main diagonal ; when k=positive means Upper diagonal ; when k=negative means Lower diagonal- The default datatype is float31. Identity Array - np.identity() - It returns an identity array i.e., a square array with 1 on the main diagonal and all other elements are 0.Syntax: np.identity(shape, dtype)- It takes a single integer value only as shape.- The No. of Rows and No. of Columns will be equal to the given integer value.- The default datatype is float32. Ones Like Array - It returns an array of Ones, with the same shape & type as of the given array.Syntax: np.ones_like(array, dtype)Ex: A = np.ones_like(B) - It will return an array A of Ones, of same shape & type as of the given already created array B.33. Zeros Like Array - It returns an array of Zeros, with the same shape & type as of the given array.Syntax: np.zeros_like(array, dtype)Ex: P = np.zeros_like(Q) - It will return an array P of Zeros, of same shape & type as of the given already created array Q.34. Full Like Array - It returns a full array of Constant element, with the same shape & type as of the given array.Syntax: np.full_like(array, fill_value, dtype)Ex: X = np.full_like(Y, 7) - It will return an array X filled with constant value 7, of same shape & type as of the given already created array Y.35. Diagonal Function - It is used to extract the diagonal elements of an array, or , used to construct a new diagonal array.Syntax: np.diag(a, k)- If 'a' is a 2-D array, it extracts the diagonal elements.- If 'a' is a 1-D array, it constructs a 2-D array with elements of 'a' on diagonal.- By default, k is 0. Use k>0 for diagonals above the main diagonal. Use k2] # It is used to select the elements of an array that satisfy some condition.48..dot() # It is used to compute inner product of the vectors, to multiply a vector by matrix, & to multiply matrixes.49. np.any(x > 0.9) # It checks if any value is greater than 0.9 in x. ( x = np.random.random(10))50. np.all(x >= 0.9) # It checks if all values are greater than or equal to 0.1 in x. ( x = np.random.random(10))51. array_A[array_A == x] = y # Replacing all x in the given array_A with y.52. a[[2,4]] or a[(1,3),:] # Getting the values from 2nd and 4th row of the matrix.53. To get the results from the matrix: a.sum(), a.std(), a.var(), a.mean(), a.max(), a.min()

课程标签

0人关注该课程

主题相关的课程