python中linspace函数_numpy.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.
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')
[]
>>> plt.plot(x2, y + 0.5, 'o')
[]
>>> plt.ylim([-0.5, 1])
(-0.5, 1)
>>> plt.show()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
时间: 2019-05-25
python中linspace函数_numpy.linspace函数具体使用详解相关推荐
- python数组相减_对Python 中矩阵或者数组相减的法则详解
对Python 中矩阵或者数组相减的法则详解 最近在做编程练习,发现有些结果的值与答案相差较大,通过分析比较得出结论,大概过程如下: 定义了一个计算损失的函数: def error(yhat,labe ...
- 站长在线Python精讲:在Python中使用正则表达式的sub()方法替换字符串详解
欢迎你来到站长在线的站长学堂学习Python知识,本文学习的是<在Python中使用正则表达式的sub()方法替换字符串详解>. 在Python中使用正则表达式的sub()方法替换字符串. ...
- python中requests库的用途-python中requests库session对象的妙用详解
在进行接口测试的时候,我们会调用多个接口发出多个请求,在这些请求中有时候需要保持一些共用的数据,例如cookies信息. 妙用1 requests库的session对象能够帮我们跨请求保持某些参数,也 ...
- python os模块安装方法_基于python中pygame模块的Linux下安装过程(详解)
一.使用pip安装Python包 大多数较新的Python版本都自带pip,因此首先可检查系统是否已经安装了pip.在Python3中,pip有时被称为pip3. 1.在Linux和OS X系统中检查 ...
- Python中第三方库Requests库的高级用法详解
Python中第三方库Requests库的高级用法详解 虽然Python的标准库中urllib2模块已经包含了平常我们使用的大多数功能,但是它的API使用起来让人实在感觉不好.它已经不适合现在的时代, ...
- 站长在线Python精讲:在Python中使用正则表达式的split()方法分割字符串详解
欢迎你来到站长在线的站长学堂学习Python知识,本文学习的是<在Python中使用正则表达式的split()方法分割字符串详解>. 使用正则表达式分割字符串 在Python中使用正则表达 ...
- python url解码_对python中url参数编码与解码的实例详解
一.简介 在python中url,对于中文等非ascii码字符,需要进行参数的编码与解码. 二.关键代码 1.url编码 对字符串编码用urllib.parse包下的quote(string, saf ...
- python中装饰器的作用_Python装饰器详解,详细介绍它的应用场景
装饰器的应用场景附加功能 数据的清理或添加:函数参数类型验证 @require_ints 类似请求前拦截数据格式转换 将函数返回字典改为 JSON/YAML 类似响应后篡改为函数提供额外的数据 moc ...
- python中backward_pytorch的梯度计算以及backward方法详解
基础知识 tensors: tensor在pytorch里面是一个n维数组.我们可以通过指定参数reuqires_grad=True来建立一个反向传播图,从而能够计算梯度.在pytorch中一般叫做d ...
- python中 a or b 的值为_详解python中and和or的返回值
在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样,但是它们并不返回布尔值:而是,返回它们实际进行比较的值之一. 一.and:>>> 'a' and 'b' ' ...
最新文章
- 关于object references an unsaved transient instance - save the transient instance before flushing的解决方法
- 小程序点击图片自动播放视频,停止上一个视频播放
- SharePoint2010是个什么东西
- 在PPT中通过插入重叠的图形获得新的图形
- windows环境搭建ios+xcode
- 如何把 DropDownList 某一个 Item 的 Text 改成粗体 ?
- gyp linux,gyp编译工具
- 穿背心的老院士,86岁,重病,还在敲代码,单手!
- 谷歌跟oracle_谁赢得了Google VS Oracle? 开发人员赢了。
- android如何阻塞主线程,Android-Android如何避免阻塞主线程
- 单张图片上传预览【超简洁,未完待续】
- An Overview of MITRE Cyber Situational Awareness Solutions
- 使用pyinstaller讲python文件打包成exe文件运行时,弹出命令行界面
- java jbpm工作流_JBPM工作流
- 2021年通达信指标公式大全,值得收藏!
- android贪吃蛇设计报告,贪吃蛇游戏报告毕业设计android
- jQuery源码解读一
- 解决ubuntu安装软件has install-snap change in progress错误
- python 实时打印控制台输出信息
- javaweb response