1. shape函数是numpy.core.fromnumeric中的函数,它的功能是查看矩阵或者数组的维数。
>>> e = eye(3) >>> e array([[ 1., 0., 0.], [ 0., 1., 0.], [ 0., 0., 1.]]) >>> e.shape (3, 3)
>>> c = array([[1,1],[1,2],[1,3],[1,4]]) >>> c.shape (4, 2) >>> c.shape[0] 4 >>> c.shape[1] 2
2.tile 函数
tile函数是模板numpy.lib.shape_base中的函数。函数的形式是tile(A,reps)
A的类型几乎所有类型都可以:array, list, tuple, dict, matrix以及基本数据类型int, string, float以及bool类型。
reps的类型也很多,可以是tuple,list, dict, array, int,bool.但不可以是float, string, matrix类型。行列重复copy的次数。
>>> tile(3,2) array([ 3, 3]) >>> tile((1,2,3),2) array([1, 2, 3, 1, 2, 3]) >>> a=[[1,2,3],[4,5,5]] >>> tile(a,2) array([[1, 2, 3, 1, 2, 3], [4, 5, 5, 4, 5, 5]]) >>> tile(a,[2,1]) >>> a=[[1,2,3],[1,2,3],[4,5,5],[4,5,5]]
3. sum函数
sum函数中加入参数。sum(a,axis=0)或者是.sum(axis=1)
axis=0 就是普通的相加 ;加入axis=1以后就是将一个矩阵的每一行向量相加
import numpy as np
np.sum([[1,2,3],[2,,3,4],axis=1)的结果就是:array([6,9])
4.argsort函数
1.先定义一个array数据
1 import numpy as np 2 x=np.array([1,4,3,-1,6,9])
2.现在我们可以看看argsort()函数的具体功能是什么:
x.argsort()
输出定义为y=array([3,0,2,1,4,5])。
我们发现argsort()函数是将x中的元素从小到大排列,提取其对应的index(索引),然后输出到y。例如:x[3]=-1最小,所以y[0]=3,x[5]=9最大,所以y[5]=5。
来源:https://www.cnblogs.com/jiangyaju/p/8072407.html