1. numpy.linspace
经常性会遇到numpy.linspace,但是开始的时候会忘记其属性,现在以API为目击点。
这里会看到numpy.linsapce(start, stop, num=50, endpoint=True, restep=False, dtype=None)这样的一个形式,使用numpy.linspace是返回等差序列,序列范围在(start, end),生成num个元素的np数组,如果endpoint为False,则生成num+1个但是返回num个,restep=True则是在其后返回步长。
>>> np.linspace(2.0, 3.0, num=5)
array([ 2. , 2.25, 2.5 , 2.75, 3. ])
>>> np.linspace(2.0, 3.0, num=5, endpoint=False)
array([ 2. , 2.2, 2.4, 2.6, 2.8])
>>> np.linspace(2.0, 3.0, num=5, retstep=True)
(array([ 2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)
2.numpy.random
2.1 numpy.random.shuffle
那么这里就应该是让训练数据集中的数据打乱顺序,然后一个挨着一个地(for i in indices)生成训练数据对。
>>> arr = np.arange(10)
>>> np.random.shu