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系列之数据处理编程实例(二)
May 22 Python
Python中if __name__ == &quot;__main__&quot;详细解释
Oct 21 Python
Python基础入门之seed()方法的使用
May 15 Python
Linux中安装Python的交互式解释器IPython的教程
Jun 13 Python
pygame实现弹力球及其变速效果
Jul 03 Python
python使用logging模块发送邮件代码示例
Jan 18 Python
使用python脚本实现查询火车票工具
Jul 19 Python
tensor和numpy的互相转换的实现示例
Aug 02 Python
Python 爬虫实现增加播客访问量的方法实现
Oct 31 Python
Python二维数组实现求出3*3矩阵对角线元素的和示例
Nov 29 Python
Python hashlib加密模块常用方法解析
Dec 18 Python
pandas的相关系数与协方差实例
Dec 27 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
phpBB BBcode处理的漏洞
2006/10/09 PHP
PHPStrom中实用的功能和快捷键大全
2015/09/23 PHP
JQuery 学习笔记 选择器之五
2009/07/23 Javascript
javascript当onmousedown、onmouseup、onclick同时应用于同一个标签节点Element
2010/01/05 Javascript
javascript innerText和innerHtml应用
2010/01/28 Javascript
js的2种继承方式详解
2014/03/04 Javascript
jquery检测input checked 控件是否被选中的方法
2014/03/26 Javascript
javascript学习笔记(四)function函数部分
2014/09/30 Javascript
Vue.js报错Failed to resolve filter问题的解决方法
2016/05/25 Javascript
Bootstrap三种表单布局的使用方法
2016/06/21 Javascript
第三篇Bootstrap网格基础
2016/06/21 Javascript
javascript读取文本节点方法小结
2016/12/15 Javascript
JavaScript表单验证完美代码
2017/03/02 Javascript
JS实现按钮颜色切换效果
2020/09/05 Javascript
微信小程序 Animation实现图片旋转动画示例
2018/08/22 Javascript
对类Vue的MVVM前端库的实现代码
2018/09/07 Javascript
vue+Element-ui实现分页效果实例代码详解
2018/12/10 Javascript
bootstrap-table实现表头固定以及列固定的方法示例
2019/03/07 Javascript
js设置默认时间跨度过程详解
2019/07/17 Javascript
利用JS响应式修改vue实现页面的input值
2019/09/02 Javascript
vue ssr+koa2构建服务端渲染的示例代码
2020/03/23 Javascript
[00:09]DOTA2新版本PA至宝特效动作展示
2014/11/19 DOTA
python实现用户管理系统
2018/01/10 Python
python实现下载pop3邮件保存到本地
2018/06/19 Python
python+opencv+caffe+摄像头做目标检测的实例代码
2018/08/03 Python
python实现图片插入文字
2019/11/26 Python
解决pyecharts运行后产生的html文件用浏览器打开空白
2020/03/11 Python
Python tkinter之ComboBox(下拉框)的使用简介
2021/02/05 Python
美国在线工具商店:Acme Tools
2018/06/26 全球购物
Java中有几种类型的流?JDK为每种类型的流提供了一些抽象类以供继承,请说出他们分别是哪些类
2012/02/06 面试题
教师推荐信范文
2013/11/24 职场文书
兴趣小组活动总结
2014/05/05 职场文书
大跃进口号
2014/06/16 职场文书
金砖之国观后感
2015/06/11 职场文书
2015年环境监察工作总结
2015/07/23 职场文书
MySQL范围查询优化的场景实例详解
2022/06/10 MySQL