numpy的基本属性
2.a.dtype 类型
3.a.shape 形状
4.a.itemsize 大小
5.a.T 转置
6.a.ndim 维度
7.mp.version 版本
8.图例:
![在这里插入图
numpy中的切片
我们以a = np.array(([1,2],[4,5],[6,7])) 创造数组:
-
a[1::1];表示从[4,5]开始切片,步长为1。
-
a[1:3:1];表示从[4,5]开始切片,索引为3的结束,步长为1。
![在这里插入图片描述](https://img-blog.csdnimg.cn/20201110165340632.png#pic_center3.a[0:0:-1];表示从索引0开始切片,索引为0的结束,步长为-1。
-
a[::-1];表示所有切片,步长为-1,相当于倒序。
-
a.np.arange(18).reshape(3,3,2);表示0~17,共18个数=332,原型改变,变成3维3行2列的数组了,之前是一维。
-
a.resize(3,6).shape ,resize可以改变原数据的形状,而shape只能改变表面的,reshape改变原数据。凡是带re的要慎重。
numpy 的铺平,展开与拼接
-
a.ravel()和 a.flatten() 都有展开的,铺平的意义。
-
c为shape(2,2),d为(2,2),np.hstack 左右拼,np.vstack 上下拼。
-
np.stack((c,d)),全拼 2维,带2括号,4维带4括号!!!
numpy 的 排序与运算
-
- a = arange(16).reshape(4,4) 将其排序,按照axis = 0 每列由小到大排序。
- 具体是指np.sort(a)的每个元素从小到大排序,np.argsort(a)指排序后元素索引的位置。
- a = arange(16).reshape(4,4) 将其排序,按照axis = 0 每列由小到大排序。
-
a与b 的运算,维度至少有行或列相同,才能进行运算。
-
a 是矩阵,a.shape = b.shape。
12.求各元素的均值,两种方法都可以。
13. a = np.array([3,5,4],[5,6,7]) 及 unique去重变1维
14. 数组运算求和及累乘。
numpy 中的列表,数组,矩阵相互转换
- L 为列表 ,b 为np.mat矩阵,L为np.array数组
2.np.mat(L).tolist 矩阵转化为列表,np.array(L)列表转化为数组,np.mat(L).getA() 矩阵转化为数组。
3.查看python 中的类
PS:
撤销:Ctrl/Command + Z
重做:Ctrl/Command + Y
加粗:Ctrl/Command + B
斜体:Ctrl/Command + I
标题:Ctrl/Command + Shift + H
无序列表:Ctrl/Command + Shift + U
有序列表:Ctrl/Command + Shift + O
检查列表:Ctrl/Command + Shift + C
插入代码:Ctrl/Command + Shift + K
插入链接:Ctrl/Command + Shift + L
插入图片:Ctrl/Command + Shift + G
查找:Ctrl/Command + F
替换:Ctrl/Command + G