numpy.tile(A, resps)
numpy.tile(A, reps)
tile的意思是瓦片, 而函数的意思是由一个瓦片堆叠形成一个图形
A:input_array,输入数组
reps: the number of repetitions of A along each axis(沿着每一个轴的对A的重复次数)
import numpy as np
A = [2, 3]
#沿着第一个轴将A重复3次
arr = np.tile(A, 2)
#沿着轴1重复2两次, 沿着轴2重复2次
arr = np.tile(A, (2,2))
numpy.sum(axis)
求和, axis参数是第几根轴, axis=1, 第一根轴求和
#沿着x轴求和, 即是球每一行的和
arr.sum(axis=1)
numpy.ndarray
numpy中最著名的对象莫过于ndarray(n dimension array, n维数组)
import numpy as np
#创建一个numpy.ndarray对象
arr = np.array([[1.0,1.1], [1.0,1.0], [0,0], [0,0.1]])
#行数
rows = arr.shape[0]
#列数
cols = arrr.shape[1]
numpy.ndarray.argsort(axis, kind, order)
return:Array of indices that sort ‘A’ along specified axis, if ‘A’ is one-dimensional.
def createDataSet():
group = np.array([[1.0,1.1], [1.0,1.0], [0,0], [0,0.1]])
labels = ['A', 'A', 'B', 'B']
return group, labels
group, labels = createDataSet()
print(group)
#按照列对矩阵的每一列排序
arr = group.argsort(axis=0)
print(arr)