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获取电脑硬件信息及状态的实现方法
Aug 29 Python
python使用PIL模块实现给图片打水印的方法
May 22 Python
python中os和sys模块的区别与常用方法总结
Nov 14 Python
基于Python中求和函数sum的用法详解
Jun 28 Python
对tensorflow 的模型保存和调用实例讲解
Jul 28 Python
详解python编译器和解释器的区别
Jun 24 Python
python/Matplotlib绘制复变函数图像教程
Nov 21 Python
tensorflow之自定义神经网络层实例
Feb 07 Python
浅谈PyTorch的可重复性问题(如何使实验结果可复现)
Feb 20 Python
在django项目中导出数据到excel文件并实现下载的功能
Mar 13 Python
Python使用多进程运行含有任意个参数的函数
May 02 Python
tensorflow 2.1.0 安装与实战教程(CASIA FACE v5)
Jun 30 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
深入解析Session是否必须依赖Cookie
2013/08/02 PHP
简单实用的PHP防注入类实例
2014/12/05 PHP
php each 返回数组中当前的键值对并将数组指针向前移动一步实例
2016/11/22 PHP
php实现查询功能(数据访问)
2017/05/23 PHP
window.parent调用父框架时 ie跟火狐不兼容问题
2009/07/30 Javascript
分享十五个最佳jQuery 幻灯插件和教程
2010/03/27 Javascript
JQuery 选项卡效果(JS与HTML的分离)
2010/04/01 Javascript
jQuery学习总结之元素的相对定位和选择器(持续更新)
2011/04/26 Javascript
使用基于jquery的gamequery插件做JS乒乓球游戏
2011/07/31 Javascript
js获取select默认选中的Option并不是当前选中值
2014/05/07 Javascript
js动态添加表格数据使用insertRow和insertCell实现
2014/05/22 Javascript
javascript从image转换为base64位编码的String
2014/07/29 Javascript
基于substring()和substr()的使用以及区别(实例讲解)
2017/12/28 Javascript
jQuery简单实现的HTML页面文本框模糊匹配查询功能完整示例
2018/05/09 jQuery
JS实现json对象数组按对象属性排序操作示例
2018/05/18 Javascript
详解vue+webpack+express中间件接口使用
2018/07/17 Javascript
详解vue axios二次封装
2018/07/22 Javascript
原生js实现贪食蛇小游戏的思路详解
2019/11/26 Javascript
Element-UI+Vue模式使用总结
2020/01/02 Javascript
vue单应用在ios系统中实现微信分享功能操作
2020/09/07 Javascript
pyqt和pyside开发图形化界面
2014/01/22 Python
详解python之多进程和进程池(Processing库)
2017/06/09 Python
python 实现对数据集的归一化的方法(0-1之间)
2018/07/17 Python
在python中安装basemap的教程
2018/09/20 Python
Python实现的各种常见分布算法示例
2018/12/13 Python
python 操作mysql数据中fetchone()和fetchall()方式
2020/05/15 Python
Python爬虫实例——爬取美团美食数据
2020/07/15 Python
碧欧泉美国官网:Biotherm美国
2016/08/31 全球购物
印度购物网站:TATA CLiQ
2017/11/23 全球购物
伯利陶器:Burleigh Pottery
2018/01/03 全球购物
优秀的教师个人的中文求职信
2013/09/21 职场文书
护士实习鉴定范文
2013/12/22 职场文书
《值日生》教学反思
2014/02/17 职场文书
《学棋》教后反思
2014/04/14 职场文书
高三学生评语大全
2014/04/25 职场文书
材料成型及控制工程专业求职信
2014/06/19 职场文书