np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
1 | start标量 |
1 | x = np.linspace(-1, 1, 5) |
np.random.normal(loc=0.0, scale=1.0, size=None)
1 | loc:float或array_like浮点数 |
输出一个均值为0,标准差为0.05的(4,3)矩阵1
2
3
4
5
6
7
8n = np.random.normal(0,0.05,[4,3])
out:
array([[ 0.00875909, 0.04187258, 0.03422398],
[ 0.04415144, 0.00083901, 0.06574384],
[ 0.13169391, 0.09001974, -0.0384982 ],
[ 0.00414203, 0.03999768, -0.09010478]])
np.newaxis
作用为增加维度。
1 | x_data=np.linspace(-1,1,300)[:,np.newaxis] |
意思为,从-1到1均匀取出300个间隔数字(包括-1,1),得到shape为(300,)的array,增加一个维度,变为(300,1)。
实际上可以使用reshape做到。
等价于1
x_data=np.linspace(-1,1,300).reshape(300,-1)