python numpy库linspace相同间隔采样的实现


Posted in Python onFebruary 25, 2020

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()

python numpy库linspace相同间隔采样的实现

以上这篇python numpy库linspace相同间隔采样的实现就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python中使用glob和rmtree删除目录子目录及所有文件的例子
Nov 21 Python
通过5个知识点轻松搞定Python的作用域
Sep 09 Python
Python基于回溯法解决01背包问题实例
Dec 06 Python
Python实现钉钉发送报警消息的方法
Feb 20 Python
python区块及区块链的开发详解
Jul 03 Python
Django使用 Bootstrap 样式修改书籍列表过程解析
Aug 09 Python
在tensorflow中设置保存checkpoint的最大数量实例
Jan 21 Python
基于Tensorflow:CPU性能分析
Feb 10 Python
Python实现检测文件的MD5值来查找重复文件案例
Mar 12 Python
在pycharm中关掉ipython console/PyDev操作
Jun 09 Python
Python GUI之tkinter窗口视窗教程大集合(推荐)
Oct 20 Python
Python os和os.path模块详情
Apr 02 Python
Pandas时间序列:时期(period)及其算术运算详解
Feb 25 #Python
基于pygame实现童年掌机打砖块游戏
Feb 25 #Python
python GUI库图形界面开发之PyQt5拖放控件实例详解
Feb 25 #Python
python GUI库图形界面开发之PyQt5美化窗体与控件(异形窗体)实例
Feb 25 #Python
Python对wav文件的重采样实例
Feb 25 #Python
python实现打砖块游戏
Feb 25 #Python
Python实现企业微信机器人每天定时发消息实例
Feb 25 #Python
You might like
PHP has encountered a Stack overflow问题解决方法
2014/11/03 PHP
PHP动态编译出现Cannot find autoconf的解决方法
2014/11/05 PHP
PHP加密解密实例分析
2015/12/25 PHP
php获取POST数据的三种方法实例详解
2016/12/20 PHP
PHP使用xpath解析XML的方法详解
2017/05/20 PHP
thinkPHP框架自动填充原理与用法分析
2018/04/03 PHP
php 字符串中是否包含指定字符串的多种方法
2018/04/12 PHP
Yii2.0实现的批量更新及批量插入功能示例
2019/01/29 PHP
在thinkphp5.0路径中实现去除index.php的方式
2019/10/16 PHP
Jquery api 速查表分享
2015/01/12 Javascript
通过js获取上传的图片信息(临时保存路径,名称,大小)然后通过ajax传递给后端的方法
2015/10/01 Javascript
js实现右键菜单功能
2016/11/28 Javascript
js使用highlight.js高亮你的代码
2017/08/18 Javascript
vue实现验证码按钮倒计时功能
2018/04/10 Javascript
element-ui中的select下拉列表设置默认值方法
2018/08/24 Javascript
vue多级复杂列表展开/折叠及全选/分组全选实现
2018/11/05 Javascript
uniapp实现横向滚动选择日期
2020/10/21 Javascript
使用Python生成url短链接的方法
2015/05/04 Python
python 基础教程之Map使用方法
2017/01/17 Python
Python 列表(List) 的三种遍历方法实例 详解
2017/04/15 Python
Python基于hashlib模块的文件MD5一致性加密验证示例
2018/02/10 Python
几行Python代码爬取3000+上市公司的信息
2019/01/24 Python
numpy.linalg.eig() 计算矩阵特征向量方式
2019/11/29 Python
Python递归函数特点及原理解析
2020/03/04 Python
python制作抽奖程序代码详解
2021/01/15 Python
Roots加拿大官网:加拿大休闲服饰品牌
2016/10/24 全球购物
澳大利亚最好的电动自行车:Leon Cycle
2020/12/19 全球购物
幼儿园教师辞职信
2014/01/18 职场文书
运动会广播稿500字
2014/01/28 职场文书
幼儿园大班教学反思
2014/02/10 职场文书
社区母亲节活动记录
2014/03/06 职场文书
新春寄语大全
2014/04/09 职场文书
探亲假请假条
2014/04/11 职场文书
蜗居观后感
2015/06/11 职场文书
pytorch Dropout过拟合的操作
2021/05/27 Python
Nginx反向代理学习实例教程
2021/10/24 Servers