SVM中用到的Numpy、matplotlib函数

numpy.meshgrid

输入坐标向量返回对应的矩阵。
Return coordinate matrices from coordinate vectors.

np.meshgrid(x1,x2,...,indexing,sparse=False,copy)

x = np.arange(-5, 5, 0.1)
y = np.arange(-5, 5, 0.1)
xx, yy = meshgrid(x, y, sparse=True)
z = np.sin(xx**2 + yy**2) / (xx**2 + yy**2)
h = plt.contourf(x,y,z)
plt.show()

matplotlib.pyplot.contour

contour()画轮廓线(等高线);
contourf()填充等高线。

numpy.r_

默认按照行合并

>>>a=np.array([[1,2,3],[4,5,6]])
>>>np.r_[a,a]
array([[1, 2, 3],
       [4, 5, 6],
       [1, 2, 3],
       [4, 5, 6]])

给出了合并轴则按照指定轴合并

>>>np.r_['-1',a,a]
array([[1, 2, 3, 1, 2, 3],
       [4, 5, 6, 4, 5, 6]])

使用‘r’或‘c’生成矩阵

>>>np.r_['r',[1,2,3], [4,5,6]]
matrix([[1, 2, 3, 4, 5, 6]])

numpy.ravel()

返回连续扁平的数组(Return a contiguous flattened array)

numpy.ravel(a,order='C')
a:输入的数组;
order:包括‘C’、‘F’、‘A’、‘K’;a中的元素将按照索引的顺序读取;

x = np.array([[1, 2, 3], [4, 5, 6]])
x.ravel()
[1 2 3 4 5 6]

在一个二位数组中,
‘C’ :row-major, C-style order,在内存中按行存储,按行计算比较快;
‘F’ :column-major, Fortran-style order,在内存中按列存储,按列计算较快;

C contiguous,Fortran contiguous 详见:
https://stackoverflow.com/questions/26998223/what-is-the-difference-between-contiguous-and-non-contiguous-arrays

你可能感兴趣的:(SVM中用到的Numpy、matplotlib函数)