numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
功能:生成一个指定间隔数的数组。
参数:(1)start:序列的起始值(2)stop:序列的终止值(3)生成的样本数(默认值=50)
(4)endpoint:该值取True时,序列的终止值包括stop;反之不包括。
(5)retstep:该值取True时,生成的数组中显示间距;反正不显示。
(6)dtype:数据类型;输出数组的类型。如果没有给出dtype,则从其他输入参数中推断数据类型。
例子:
>>>numpy.linspace(1,10,10)
>>>array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])
>>>numpy.linspace(1,10,10,endpoint = False)
>>>array([ 1. , 1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1])
>>>numpy.linspace(1,10,10,retstep= True)
>>>(array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.]), 1.0)
拓展例子:
>>>numpy.linspace(1,10,10).reshape([10,1])
>>>array([[ 1.],
[ 2.],
[ 3.],
[ 4.],
[ 5.],
[ 6.],
[ 7.],
[ 8.],
[ 9.],
[ 10.]])