# python-numpy **Repository Path**: carmeloLee/python-numpy ## Basic Information - **Project Name**: python-numpy - **Description**: Python Numpy - **Primary Language**: Python - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 1 - **Forks**: 0 - **Created**: 2022-07-25 - **Last Updated**: 2022-08-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: Python, numpy ## README # python-numpy使用说明 ### Numpy介绍 ###### 1、主页: https://numpy.org/ ###### 2、numpy = Numerical Python科学计算库,用于快速高效地处理任意维度的数组 ###### 3、ndarray: 多维数组,numpy的核心数据结构 ### Numpy与Python原生List的优劣势 1、ndarray只能存储相同类型的数据,通用性没有Python原生List强;ndarray数据是连续存储的; 2、ndarray支持并行运算; 3、numpy底层是C语言开发的,性能不受Python解释器影响; ### 数组的拷贝,示例见"09数组的复制.py" 1、np.asarray(): 浅拷贝 2、np.copy(): 深拷贝 3、np.array(): 深拷贝 ### 04随机数创建会与matplotlib绘图库联动 ### ndarray修改数组的3种方法,示例见"08二维数组的切片和索引使用.py"、"13数组的转置.py" 1、rtnVal = ndarray.reshape(): 返回新的ndarray对象 2、ndarray.resize(): 对原来的ndarray对象的shape做改变 3、ndarray.T: 数组的行列转置 ### broadcast广播机制: numpy两个数组之间运算时,需要满足以下任意一个条件才能运算 1、维度相等; 2、数组的shape (其中相对应的一个地方为1) ###### 3维数组 (256 x 256 x 3) 和1维数组 (3): 满足要求1, 因为数组的第一维都是3,数值相等; ###### 4维数组 (9 x 1 x 7 x 1) 和3维数组 (8 x 1 x 5): 满足要求2, 因为对应的位置上都有1; ###### 3维数组 (15 x 3 x 5) 和3维数组 (15 x 1 x 1): 满足要求1和2, 因为1、2维上的值都有1,3维的数值相等; A: 15 x 3 x 5 B: 15 x 1 x 1 A+B: 15 x 3 x 5 ### 矩阵的乘法 (m, n) x (n, l) => (m, l) ######数组和矩阵的区别 1、数组之间的运算需要遵循broadcast广播机制; 2、矩阵之间的运算(m, n) x (n, l) => (m, l),不用遵守broadcast机制;