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 输出一个两行字符的变量
Feb 05 Python
Python 不同对象比较大小示例探讨
Aug 21 Python
在Python中利用Pandas库处理大数据的简单介绍
Apr 07 Python
django限制匿名用户访问及重定向的方法实例
Feb 07 Python
python检测主机的连通性并记录到文件的实例
Jun 21 Python
Python 实现「食行生鲜」签到领积分功能
Sep 26 Python
python 图片去噪的方法示例
Jul 09 Python
python 计算两个列表的相关系数的实现
Aug 29 Python
500行代码使用python写个微信小游戏飞机大战游戏
Oct 16 Python
Pytorch 搭建分类回归神经网络并用GPU进行加速的例子
Jan 09 Python
Python使用进程Process模块管理资源
Mar 05 Python
django实现模板中的字符串文字和自动转义
Mar 31 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过滤危险html代码
2008/08/18 PHP
基于php中使用excel的简单介绍
2013/08/02 PHP
新浪SAE云平台下使用codeigniter的数据库配置
2014/06/12 PHP
php禁止浏览器使用缓存页面的方法
2014/11/07 PHP
php常用字符串比较函数实例汇总
2014/11/24 PHP
PHP中利用sleep函数实现定时执行功能实现代码
2016/08/25 PHP
php中通过eval实现字符串格式的计算公式
2017/03/18 PHP
JS中类或对象的定义说明
2014/03/10 Javascript
轻松创建nodejs服务器(9):实现非阻塞操作
2014/12/18 NodeJs
Highcharts+NodeJS搭建数据可视化平台示例
2017/01/01 NodeJs
javascript闭包的使用之按钮切换功能
2018/08/30 Javascript
深入浅析Node.js 事件循环、定时器和process.nextTick()
2018/10/22 Javascript
浅析Vue.js 中的条件渲染指令
2018/11/19 Javascript
JavaScript判断浏览器版本的方法
2019/11/03 Javascript
js防抖函数和节流函数使用场景和实现区别示例分析
2020/04/11 Javascript
在Python中操作文件之seek()方法的使用教程
2015/05/24 Python
Python中集合的内建函数和内建方法学习教程
2015/08/19 Python
整理Python 常用string函数(收藏)
2016/05/30 Python
使用Python 正则匹配两个特定字符之间的字符方法
2018/12/24 Python
pyinstaller打包单个exe后无法执行错误的解决方法
2019/06/21 Python
Python并发请求下限制QPS(每秒查询率)的实现代码
2020/06/05 Python
中国茶叶、茶具一站式网上购物商城:醉品茶城
2018/07/03 全球购物
荷兰鞋类购物网站:Donelli
2019/05/24 全球购物
英国伦敦的睡衣品牌:Asceno
2019/10/06 全球购物
巴西24小时在线药房:Drogasil
2020/06/20 全球购物
屈臣氏泰国官网:Watsons TH
2021/02/23 全球购物
《落花生》教学反思
2014/02/25 职场文书
小学生国旗下演讲稿
2014/04/25 职场文书
个人承诺书格式
2014/06/03 职场文书
我与祖国共奋进演讲稿
2014/09/13 职场文书
2014年银行信贷员工作总结
2014/12/08 职场文书
2015个人年度工作总结范文
2015/05/28 职场文书
青年教师听课心得体会
2016/01/15 职场文书
车辆挂靠协议书
2016/03/23 职场文书
python实现简单区块链结构
2021/04/25 Python
SpringBoot2零基础到精通之数据与页面响应
2022/03/22 Java/Android