numpy
参数:
[返回指定间隔(start和stop之间)之间的等距数字]
Return evenly spaced numbers over a specified interval.
[返回“num”等距采样,按间隔[`start`,`stop`]计算。]
Returns `num` evenly spaced samples, calculated over the interval [`start`, `stop`].
[可以选择是否排除间隔的终点]
The endpoint of the interval can optionally be excluded.
[现在支持非标量"start"和"stop"]
Non-scalar `start` and `stop` are now supported.
参数含义:
start:样本数据开始点。
stop:样本数据结束点。
num:生成的样本数据量,默认为50。
endpoint:默认为True,包含stop;若为False,则不包含stop。
retstep:默认为False。若为True,则结果会给出数据间隔,array([])变成了(array([]),step)
其中sample的数据类型是numpy.ndarray,step的数据类型是float
dtype:输出数组类型,可以选择输出的数组是整型还是浮点型或者布尔型。
axis:默认为0。可以选择-1
与linspace类似用法的还有:
arange:类似于“linspace”,但使用步长(step size)
geomspace:与“linspace”类似,但数字在日志上均匀分布比例(几何级数)。
logspace:类似于“geomspace”,但其端点(endpoints)指定为对数。
Examples:
>>> np.linspace(2, 3, num=5)
array([2. , 2.25, 2.5 , 2.75, 3. ])
>>> np.linspace(2, 3, num=5, endpoint=False)
array([2. , 2.2, 2.4, 2.6, 2.8])
>>> np.linspace(2, 3, num=5, retstep=True)
(array([2. , 2.25, 2.5 , 2.75, 3. ]), 0.25)
>>> np.linspace(2, 3, num=5, retstep=True,dtype=float)
(array([2, 2, 2, 2, 3]), 0.25)
# plt可视化
>>> import matplotlib.pyplot as plt
>>> x1 = np.linspace(0, 10, num=8, endpoint=True)
>>> x2 = np.linspace(0, 10, num=8, endpoint=False)
# 用0填充,一维
>>>y=np.zeros(8)
>>> plt.plot(x1, y, 'o')
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.plot(x2, y + 0.5, 'o')
[<matplotlib.lines.Line2D object at 0x...>]
>>> plt.ylim([-0.5, 1])
(-0.5, 1)
>>> plt.show()
此篇笔记经本人整理后,供我日后忘了的时候查看哈哈哈哈。欢迎各位大佬提出宝贵意见。
ZCyu's python 学习笔记1