numpy.linspace函数具体使用详解


Posted in Python onMay 27, 2019

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.

See also

arange

Similar to linspace, but uses a step size (instead of the number of samples)

.arange使用的是步长,而不是样本的数量

logspace

Samples uniformly distributed in log space. 

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

numpy.linspace函数具体使用详解

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持三水点靠木。

Python 相关文章推荐
python实现系统状态监测和故障转移实例方法
Nov 18 Python
pycharm 使用心得(一)安装和首次使用
Jun 05 Python
python中pass语句用法实例分析
Apr 30 Python
python3+PyQt5实现支持多线程的页面索引器应用程序
Apr 20 Python
使用OpenCV实现仿射变换—旋转功能
Aug 29 Python
关于初始种子自动选取的区域生长实例(python+opencv)
Jan 16 Python
浅谈Python3实现两个矩形的交并比(IoU)
Jan 18 Python
Python读取文件内容为字符串的方法(多种方法详解)
Mar 04 Python
Python __slots__的使用方法
Nov 15 Python
python 实现Harris角点检测算法
Dec 11 Python
用Python提取PDF表格的方法
Apr 11 Python
python3美化表格数据输出结果的实现代码
Apr 14 Python
Django利用cookie保存用户登录信息的简单实现方法
May 27 #Python
Django框架设置cookies与获取cookies操作详解
May 27 #Python
numpy下的flatten()函数用法详解
May 27 #Python
详解numpy的argmax的具体使用
May 27 #Python
numpy.random模块用法总结
May 27 #Python
Django框架自定义session处理操作示例
May 27 #Python
numpy concatenate数组拼接方法示例介绍
May 27 #Python
You might like
默默简单的写了一个模板引擎
2007/01/02 PHP
Discuz论坛密码与密保加密规则
2016/12/19 PHP
PHP扩展类型及安装方式解析
2020/04/27 PHP
JQuery 无废话系列教程(二) jquery实战篇上
2009/06/23 Javascript
Three.js源码阅读笔记(Object3D类)
2012/12/27 Javascript
使用jQuery插件创建常规模态窗口登陆效果
2013/08/23 Javascript
jQuery实现带动画效果的二级下拉导航方法
2015/03/11 Javascript
NodeJS连接MongoDB数据库时报错的快速解决方法
2016/05/13 NodeJs
Bootstrap Paginator分页插件与ajax相结合实现动态无刷新分页效果
2016/05/27 Javascript
js实现一键复制功能
2017/03/16 Javascript
PHP7新特性简述
2017/06/11 Javascript
javaScript 连接打印机,打印小票的实例
2017/12/29 Javascript
JS表单传值和URL编码转换
2018/03/03 Javascript
解决layui中的form表单与button的点击事件冲突问题
2018/08/15 Javascript
解决Vue.js由于延时显示了{{message}}引用界面的问题
2018/08/25 Javascript
Angular2 自定义表单验证器的实现方法
2018/12/14 Javascript
vue实现搜索过滤效果
2019/05/28 Javascript
Vue多环境代理配置方法思路详解
2019/06/21 Javascript
详解Django中的ifequal和ifnotequal标签使用
2015/07/16 Python
Python的爬虫框架scrapy用21行代码写一个爬虫
2017/04/24 Python
Python中is和==的区别详解
2018/11/15 Python
python正则表达式匹配不包含某几个字符的字符串方法
2019/07/23 Python
学习Django知识点分享
2019/09/11 Python
Python调用Windows命令打印文件
2020/02/07 Python
销售代表求职自荐信
2013/10/01 职场文书
通信工程专业毕业生推荐信
2013/12/25 职场文书
事业单位请假制度
2014/01/13 职场文书
十佳班主任事迹材料
2014/01/18 职场文书
最新个人职业生涯规划书
2014/01/22 职场文书
高中课前三分钟演讲稿
2014/08/18 职场文书
教师节横幅标语
2014/10/08 职场文书
国庆节慰问信
2015/02/15 职场文书
工作自我推荐信范文
2015/03/25 职场文书
无保留意见审计报告
2015/06/05 职场文书
MySQL sql模式设置引起的问题
2022/05/15 MySQL
使用 CSS 构建强大且酷炫的粒子动画效果
2022/08/14 HTML / CSS