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实现将SQLite中的数据直接输出为CVS的方法示例
Jul 13 Python
详解Python学习之安装pandas
Apr 16 Python
Python3+Appium安装使用教程
Jul 05 Python
pandas中的series数据类型详解
Jul 06 Python
Python用字典构建多级菜单功能
Jul 11 Python
python读写csv文件并增加行列的实例代码
Aug 01 Python
Python使用循环神经网络解决文本分类问题的方法详解
Jan 16 Python
Python如何实现小程序 无限求和平均
Feb 18 Python
Python参数传递实现过程及原理详解
May 14 Python
基于python模拟bfs和dfs代码实例
Nov 19 Python
python中判断数字是否为质数的实例讲解
Dec 06 Python
python实现b站直播自动发送弹幕功能
Feb 20 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
通过ODBC连接的SQL SERVER实例
2006/10/09 PHP
用文本文件制作留言板提示(上)
2006/10/09 PHP
别人整理的服务器变量:$_SERVER
2006/10/20 PHP
利用Ext Js生成动态树实例代码
2008/09/08 Javascript
Three.js源码阅读笔记(基础的核心Core对象)
2012/12/27 Javascript
jquery对dom的操作常用方法整理
2013/06/25 Javascript
javascript关于open.window子页面执行完成后刷新父页面的问题分析
2015/04/27 Javascript
jQuery异步上传文件插件ajaxFileUpload详细介绍
2015/05/19 Javascript
jQuery实现自动滚动到页面顶端的方法
2015/05/22 Javascript
ES6中如何使用Set和WeakSet
2016/03/10 Javascript
详解AngularJS过滤器的使用
2016/03/11 Javascript
使用JSON作为函数的参数的优缺点
2016/10/27 Javascript
简单实现js浮动框
2016/12/13 Javascript
angularJS+requireJS实现controller及directive的按需加载示例
2017/02/20 Javascript
JS实现二叉查找树的建立以及一些遍历方法实现
2017/04/17 Javascript
Vue键盘事件用法总结
2017/04/18 Javascript
ionic 自定义弹框效果
2017/06/27 Javascript
vue使用ElementUI时导航栏默认展开功能的实现
2018/07/04 Javascript
谈谈JavaScript中super(props)的重要性
2019/02/12 Javascript
[07:54]DOTA2 MV《我的动力鞋》 ImbaTV 出品
2014/11/21 DOTA
纯Python开发的nosql数据库CodernityDB介绍和使用实例
2014/10/23 Python
使用Python和xlwt向Excel文件中写入中文的实例
2018/04/21 Python
Python解决线性代数问题之矩阵的初等变换方法
2018/12/12 Python
Python中一个for循环循环多个变量的示例
2019/07/16 Python
django的auth认证,authenticate和装饰器功能详解
2019/07/25 Python
python 修改本地网络配置的方法
2019/08/14 Python
Python+OpenCV实现实时眼动追踪的示例代码
2019/11/11 Python
Python PyQt5模块实现窗口GUI界面代码实例
2020/05/12 Python
在pycharm创建scrapy项目的实现步骤
2020/12/01 Python
英国最大的运动营养公司之一:LA Muscle
2018/07/02 全球购物
J2EE面试题
2016/03/14 面试题
六个一活动实施方案
2014/03/21 职场文书
社区助残日活动总结
2014/08/29 职场文书
医学专业大学生职业生涯规划书
2014/10/25 职场文书
装配车间主任岗位职责
2015/04/08 职场文书
Python djanjo之csrf防跨站攻击实验过程
2021/05/14 Python