np.linspace

np.linspace

np.linspace 给定起点、终点和项数,返回等差数列

numpy.linspace(start, stop, num=50, endpoint=True, retstep=False)

endpoint 控制终点是否取,retstep 控制是否在第二项返回公差

1
2
3
print(np.linspace(2.0, 3.0, num=5))
print(np.linspace(2.0, 3.0, num=5, endpoint=False))
print(np.linspace(2.0, 3.0, num=5, retstep=True))
1
2
3
[2.   2.25 2.5  2.75 3.  ]
[2.  2.2 2.4 2.6 2.8]
(array([2.  , 2.25, 2.5 , 2.75, 3.  ]), 0.25)