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打造出适合自己的定制化Eclipse IDE
Mar 02 Python
Python读取图片为16进制表示简单代码
Jan 19 Python
python如何让类支持比较运算
Mar 20 Python
基于python的多进程共享变量正确打开方式
Apr 28 Python
用python处理MS Word的实例讲解
May 08 Python
python 实现提取某个索引中某个时间段的数据方法
Feb 01 Python
Python3内置模块pprint让打印比print更美观详解
Jun 02 Python
django的auth认证,authenticate和装饰器功能详解
Jul 25 Python
手把手教你pycharm专业版安装破解教程(linux版)
Sep 26 Python
通过实例了解Python str()和repr()的区别
Jan 17 Python
Python操作Excel的学习笔记
Feb 18 Python
Python+Selenium实现抖音、快手、B站、小红书、微视、百度好看视频、西瓜视频、微信视频号、搜狐视频、一点号、大风号、趣头条等短视频自动发布
Apr 13 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
php部分常见问题总结
2008/03/27 PHP
PHP5中新增stdClass 内部保留类
2011/06/13 PHP
php仿QQ验证码的实例分析
2013/07/01 PHP
yii2简单使用less代替css示例
2017/03/10 PHP
javascript下判断一个元素是否存在的代码
2010/03/05 Javascript
基于jQuery中对数组进行操作的方法
2013/04/16 Javascript
AngularJS中过滤器的使用与自定义实例代码
2016/09/17 Javascript
Vue.js系列之项目结构说明(2)
2017/01/03 Javascript
element 结合vue 在表单验证时有值却提示错误的解决办法
2018/01/22 Javascript
使用vue.js在页面内组件监听scroll事件的方法
2018/09/11 Javascript
利用hasOwnProperty给数组去重的面试题分享
2018/11/05 Javascript
json 带斜杠时如何解析的实现
2019/08/12 Javascript
vue实践---根据不同环境,自动转换请求的url地址操作
2020/09/21 Javascript
[02:31]2018年度DOTA2最具人气选手-完美盛典
2018/12/16 DOTA
python计算圆周率pi的方法
2015/07/11 Python
基于Python的XSS测试工具XSStrike使用方法
2017/07/29 Python
python中os和sys模块的区别与常用方法总结
2017/11/14 Python
Python实现确认字符串是否包含指定字符串的实例
2018/05/02 Python
Python中is和==的区别详解
2018/11/15 Python
Pytorch基本变量类型FloatTensor与Variable用法
2020/01/08 Python
python第三方库学习笔记
2020/02/07 Python
Python sep参数使用方法详解
2020/02/12 Python
基于Django OneToOneField和ForeignKey的区别详解
2020/03/30 Python
django自带的权限管理Permission用法说明
2020/05/13 Python
浅谈Python __init__.py的作用
2020/10/28 Python
Carter’s OshKosh加拿大:购买婴幼儿服装和童装
2018/11/27 全球购物
全球精选男装和家居用品:Article
2020/04/13 全球购物
董事长职责范文
2013/11/08 职场文书
利群广告词
2014/03/20 职场文书
煤矿安全生产月活动总结
2014/07/05 职场文书
大学生创业计划书
2014/08/14 职场文书
2015新年寄语(一句话)
2014/12/08 职场文书
优秀团员自我评价
2015/03/10 职场文书
导游词之新疆尼雅遗址
2019/10/16 职场文书
导游词之蜀山胜景瓦屋山
2019/11/29 职场文书
MySQL里面的子查询的基本使用
2021/08/02 MySQL