统计学习方法 | 第1章 统计学习方法概论 | numpy.linspace()
numpy.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)
在指定的间隔内返回均匀间隔的数字。
返回num均匀分布的样本,在[start, stop]。
这个区间的端点可以任意的被排除在外。
Parameters(参数):
start : scalar(标量)
The starting value of the sequence(序列的起始点).
stop : scalar
序列的结束点,除非endpoint被设置为False,在这种情况下, the sequence consists of all but the last of num + 1 evenly spaced samples(该序列包括所有除了最后的num+1上均匀分布的样本(感觉这样翻译有点坑)), 以致于stop被排除.当endpoint is False的时候注意步长的大小(下面有例子).
num : int, optional(可选)
生成的样本数,默认是50。必须是非负。
endpoint : bool, optional
如果是真,则一定包括stop,如果为False,一定不会有stop
retstep : bool, optional
If True, return (samples, step), where step is the spacing between samples.(看例子)
dtype : dtype, optional
The type of the output array. If dtype is not given, infer the data type from the other input arguments(推断这个输入用例从其他的输入中).
New in version 1.9.0.
Returns:
samples : ndarray
There are num equally spaced samples in the closed interval [start, stop] or the half-open interval [start, stop) (depending on whether endpoint is True or False).
step : float(只有当retstep设置为真的时候才会存在)
Only returned if retstep is True
Size of spacing between samples.
当endpoint被设置为False的时候
>>> import numpy as np
>>> np.linspace(1, 10, 10)
array([ 1., 2., 3., 4., 5., 6., 7., 8., 9., 10.])
>>> np.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])
In [4]: np.linspace(1, 10, 10, endpoint = False, retstep= True)
Out[4]: (array([ 1. , 1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1]), 0.9)
官网的例子
Examples
>>>
>>> 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)
Graphical illustration:>>>
>>> import matplotlib.pyplot as plt
>>> N = 8
>>> y = np.zeros(N)
>>> x1 = np.linspace(0, 10, N, endpoint=True)
>>> x2 = np.linspace(0, 10, N, endpoint=False)
>>> 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()
最新文章
- DA - 信息获取途径汇总
- ndk学习6: 使用gdb调试ndk程序一
- CSS手动制作三角形图标
- iOS之 随笔-静态库创建Xcode7
- JS参考书籍
- Python标准库11 多进程探索 (multiprocessing包)
- find grep
- BZOJ 2049: [Sdoi2008]Cave 洞穴勘測 LCT
- 基于python做的抓图程序1.0.00版本
- Java程序猿面试题集(181- 199)
- Python3基础 list(reversed()) 将一个列表逆转并输出
- AngularJS进入使用前的准备工作
- day_1_登录接口
- 韩信点兵(hanxin)
- JAVA处理Blob大对象
- 【一天一道LeetCode】#12 Integer to Roman
- 安装ceph设置镜像源
- C# JSON 转换
- LOJ6387 [THUPC2018] 绿绿与串串 【manacher】
- wiki----为用户设置管理员权限
热门文章
- [Python之路] ORM(对象关系映射)
- include和require的区别(PHP版本7)
- asp.net大文件传输断点续传源码
- luogu【模板】线性筛素数 (Miller-Rabin素数测试模板)
- CodeForces 707D Persistent Bookcase ——(巧妙的dfs)
- C语言博客作业00
- Linux编程之文件锁
- SpringBoot2.X 静态文件配置
- 【黑马JavaSE】1.1JavaSE、环境变量、CMD使用、常量、变量、数据类型转换(自动/强制)、ASCII码表、Unicode万国码表
- python - linux下 no module named pip