1,numpy
1.1 ones()
根据指定参数,返回narray类型的数组
#! /usr/bin/python
# -*- encoding=utf8 -*-
import numpy as np
weight = np.ones((2, 3)) # 返回两行三列的数组
print weight
# 返回两行三列类型为int的数组
weight1 = np.ones((2, 3), np.int )
print weight1
1.2,mat()
根据参数生成矩阵
#! /usr/bin/python
# -*- encoding=utf8 -*-
import numpy as np
x = np.array([[1, 2], [3, 4]], dtype=np.float)
weight2 = np.mat(x)
print weight2
print type(weight2)
dtype指定生成矩阵的类型。
1.3,transpose()
将数组或矩阵转置
#! /usr/bin/python
# -*- encoding=utf8 -*-
import numpy as np
x = np.arange(20).reshape(4, 5)
print x
print x.transpose()
print type(x)
x = np.mat(x)
print type(x)
print x
print x.transpose()
2,matplotlib.pyplot
2.1,scatter()
scatter()函数是用来画散点图的。例如:plt.scatter(1.0, 1.0, color=’red’, marker=’o’, label=’red’, s=30)中第一二个参数表示的是坐标,除可以点入单个数组外还可以填写list和array类型的数组。第一个表示x第二个表示y值。填写数组时要一一对应。plt.scatter([1, 2], [3, 4],…)表示绘制(1,3)和(2,4)两个点。第三个参数表示的为点的颜色,常用的有“red”红色,“black”黑色,“blue”蓝色等。第四个为点的形状,’o’表示空心圆点。’x’表示叉。’+’表示+形状的点等。label参数表示图例的显示。要使此属性生效要在后面加上plt.legend(),最后一个s表示点的大小。
更新中。。。