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连接字符串的方法小结
Jul 13 Python
Django的session中对于用户验证的支持
Jul 23 Python
Pyinstaller将py打包成exe的实例
Mar 31 Python
python中yaml配置文件模块的使用详解
Apr 27 Python
flask框架实现连接sqlite3数据库的方法分析
Jul 16 Python
对python 多线程中的守护线程与join的用法详解
Feb 18 Python
windows下python虚拟环境virtualenv安装和使用详解
Jul 16 Python
python爬虫 批量下载zabbix文档代码实例
Aug 21 Python
Atom Python 配置Python3 解释器的方法
Aug 28 Python
解决python调用自己文件函数/执行函数找不到包问题
Jun 01 Python
Python如何解决secure_filename对中文不支持问题
Jul 16 Python
Python中Matplotlib的点、线形状、颜色以及绘制散点图
Apr 07 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
Yii PHP Framework实用入门教程(详细介绍)
2013/06/18 PHP
PHP文件与目录操作示例
2016/12/24 PHP
Thinkphp 空操作、空控制器、命名空间(详解)
2017/05/05 PHP
为javascript添加String.Format方法
2020/08/11 Javascript
javascript学习笔记(六) Date 日期类型
2012/06/19 Javascript
Javascript实现简单二级下拉菜单实例
2014/06/15 Javascript
jquery 设置style:display的方法
2015/01/29 Javascript
Flash图片上传组件 swfupload使用指南
2015/03/14 Javascript
javascript模拟php函数in_array
2015/04/27 Javascript
JS操作XML实例总结(加载与解析XML文件、字符串)
2015/12/08 Javascript
onclick和onblur冲突问题的快速解决方法
2016/04/28 Javascript
JQuery为元素添加样式的实现方法
2016/07/20 Javascript
JavaScript制作颜色反转小游戏
2016/09/25 Javascript
Vue学习笔记进阶篇之多元素及多组件过渡
2017/07/19 Javascript
Node.js实现连接mysql数据库功能示例
2017/09/15 Javascript
vue router使用query和params传参的使用和区别
2017/11/13 Javascript
Node.js使用Express.Router的方法
2017/11/14 Javascript
Node.js成为Web应用开发最佳选择的原因
2018/02/05 Javascript
8个有意思的JavaScript面试题
2019/07/30 Javascript
JavaScript单线程和任务队列原理解析
2020/02/04 Javascript
编写Python脚本抓取网络小说来制作自己的阅读器
2015/08/20 Python
Python语法快速入门指南
2015/10/12 Python
python结合shell查询google关键词排名的实现代码
2016/02/27 Python
基于Django filter中用contains和icontains的区别(详解)
2017/12/12 Python
Python判断字符串是否xx开始或结尾的示例
2019/08/08 Python
利用python画出AUC曲线的实例
2020/02/28 Python
详解Python中的Lock和Rlock
2021/01/26 Python
澳大利亚婴儿、幼儿和儿童在线设计师商店:Smooch Baby
2019/02/16 全球购物
英国书籍、CD、DVD和游戏的第一道德零售商:Awesome Books
2020/02/22 全球购物
大四学生思想汇报
2014/01/13 职场文书
《青蛙看海》教学反思
2014/04/23 职场文书
法律系毕业生求职信
2014/05/28 职场文书
七年级地理教学计划
2015/01/22 职场文书
幼儿园开学通知
2015/04/24 职场文书
撤诉申请怎么写
2015/05/19 职场文书
Python使用openpyxl模块处理Excel文件
2022/06/05 Python