转自:https://blog.csdn.net/ui_shero/article/details/78881067

1.np.linspace() 生成(start,stop)区间指定元素个数num的list,均匀分布

Parameters

----------

start : scalar  #scalar:标量

The starting value of the sequence.

stop : scalar

The end value of the sequence, unless `endpoint` is set to False.

In that case, the sequence consists of all but the last of ``num + 1``

evenly spaced samples, so that `stop` is excluded.  Note that the step

size changes when `endpoint` is False.

num : int, optional  #oprional:可选项

Number of samples to generate. Default is 50. Must benon-negative.

endpoint : bool, optional  #是否包括右边界点

If True, `stop` is the last sample. Otherwise, it is not included.

Default is True.

retstep : bool, optional  #返回步长
---------------------
作者:IT_Shero
来源:CSDN
原文:https://blog.csdn.net/ui_shero/article/details/78881067
版权声明:本文为博主原创文章,转载请附上博文链接!

-----------------------------------

np.linspace(2.0, 3.0, num=5, retstep=True)

(array([ 2.  ,  2.25,  2.5 ,  2.75,  3.  ]),0.25)

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])
--------------------------------

import numpy as np

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]) #设置y轴区间

(-0.5, 1)

plt.show()

2.np.logspace() log分布间距生成list

Parameters
----------
start : float  #基底base的start次幂作为左边界
    ``base ** start`` is the starting value of the sequence.
stop : float  #基底base的stop次幂作为右边界
    ``base ** stop`` is the final value of the sequence, unless `endpoint`
    is False.  In that case, ``num + 1`` values are spaced over the
    interval in log-space, of which all but the last (a sequence of
    length ``num``) are returned.
num : integer, optional
    Number of samples to generate.  Default is 50.
endpoint : boolean, optional
    If true, `stop` is the last sample. Otherwise, it is not included.
    Default is True.
base : float, optional  #基底
    The base of the log space. The step size between the elements in
    ``ln(samples) / ln(base)`` (or ``log_base(samples)``) is uniform.
    Default is 10.0.
dtype : dtype
    The type of the output array.  If `dtype` is not given, infer the data
    type from the other input arguments.
---------------------

np.logspace(2.0, 3.0, num=4)

array([  100.        ,   215.443469  ,   464.15888336,  1000.        ])

np.logspace(2.0, 3.0, num=4, endpoint=False)

array([ 100.        ,  177.827941  ,  316.22776602,  562.34132519])

np.logspace(2.0, 3.0, num=4, base=2.0)

array([ 4.        ,  5.0396842 ,  6.34960421,  8.        ])
---------------------

import numpy as np

import matplotlib.pyplot as plt

N = 10

x1 = np.logspace(0.1, 1, N, endpoint=True)

x2 = np.logspace(0.1, 1, N, endpoint=False)

y = np.zeros(N)

plt.plot(x1, y, 'o')

plt.plot(x2, y + 0.5, '<')

plt.ylim([-0.5, 1])

(-0.5, 1)

plt.show()

3.np.arange() 生成(start,stop)区间指定步长step的list

np.arange(3)

array([0, 1, 2])

np.arange(3.0)

array([ 0.,  1.,  2.])

np.arange(3,7)

array([3, 4, 5, 6])

np.arange(3,7,2)

array([3, 5])

【转】np.linspace()、np.logspace()、np.arange()的更多相关文章

  1. 区分range() , np.arange() , np.linspace()

    content: range() np.arange() np.linspace() 一.range(start, stop, step) 1.range() 为 python 自带函数 2.生成一个 ...

  2. Python中range, np.arange, np.linspace的区别

    目录 range np.arange np.linspace range 特点 range()是python内置函数,指定开始值,终值和步长生成等差数列的一维数组 不包含终值 步长只能是整数,生成整数 ...

  3. Python:range、np.arange和np.linspace

    1. range range是python内置的一个类,该类型表示一个不可改变(immutable)的数字序列,常常用于在for循环中迭代一组特殊的数,它的原型可以近似表示如下: class rang ...

  4. 深度学习原理与框架-神经网络-线性回归与神经网络的效果对比 1.np.c_[将数据进行合并] 2.np.linspace(将数据拆成n等分) 3.np.meshgrid(将一维数据表示为二维的维度) 4.plt.contourf(画出等高线图,画算法边界)

    1. np.c[a, b]  将列表或者数据进行合并,我们也可以使用np.concatenate 参数说明:a和b表示输入的列表数据 2.np.linspace(0, 1, N) # 将0和1之间的数 ...

  5. NP:建立可视化输入的二次函数数据点集np.linspace+np.random.shuffle+np.random.normal

    import numpy as np import matplotlib.pyplot as plt def fix_seed(seed=1): #重复观看一样东西 # reproducible np ...

  6. np.linspace,numpy中的linspace()

    import numpy as np x=np.linspace(1,10) y=np.linspace(1,10,num=10,retstep=True)#num可省略 print(x) print ...

  7. (数学)P、NP、NPC、NP hard问题

    概念定义: P问题:能在多项式时间内解决的问题: NP问题:(Nondeterministic Polynomial time Problem)不能在多项式时间内解决或不确定能不能在多项式时间内解决, ...

  8. 浮点型数据需要转化为int,才能作为点,被读取abc = np.array(abc, dtype=np.int)

    import cv2 import numpy as np import matplotlib.pyplot as plt img = 'test.jpg' img = cv2.imread(img) ...

  9. python中numpy库ndarray多维数组的的运算:np.abs(x)、np.sqrt(x)、np.modf(x)等

    numpy库提供非常便捷的数组运算,方便数据的处理. 1.数组与标量之间可直接进行运算 In [45]: aOut[45]:array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ ...

随机推荐

  1. 《JavaWeb从入门到改行》JDBC经典秘方QueryRunner

    目录: 基础篇_功能各自回顾 JDBC基础代码回顾(使用JdbcUtils工具简化) c3p0数据库连接池的使用(使用JdbcUtils工具简化) 大数据的插入(使用c3p0+JdbcUtils工具简 ...

  2. problem-solving-with-algorithms-and-data-structure-usingpython(使用python解决算法和数据结构) -- 算法分析

    1. 计算前n个整数的和 def sumOfN(n): theSum = 0 for i in range(1,n+1): theSum += i return theSum print(sumOfN ...

  3. Jquery使用Id获取焦点和失去焦点

    Jquery使用Id获取焦点和失去焦点有2种方法 先用第一种(val()=="空"): <div> <input type="text" id ...

  4. java.lang.NoSuchMethodError 报500

    1. 概述 mvc项目 接口报500 localhost 错误日志 07-Jan-2019 17:12:43.664 SEVERE [catalina-exec-21] org.apache.cata ...

  5. 从敲入 URL 到浏览器渲染完成、对HTTP协议的理解

    1. 大致过程 当你这样子回答的时候: 用户输入 url 地址,浏览器查询 DNS 查找对应的请求 IP 地址 建立 TCP 连接 浏览器向服务器发送 http 请求,如果服务器段返回以 301 之类 ...

  6. BZOJ3672: [Noi2014]购票(dp 斜率优化 点分治 二分 凸包)

    题意 题目链接 Sol 介绍一种神奇的点分治的做法 啥?这都有根树了怎么点分治?? 嘿嘿,这道题的点分治不同于一般的点分治.正常的点分治思路大概是先统计过重心的,再递归下去 实际上一般的点分治与统计顺 ...

  7. java 对象

      对象可以看成是静态属性和动态属性的封装体.静态属性——成员变量:动态属性——方法. 1.汇编语言是对机器语言的抽象. 2.面向过程的语言是对汇编语言的抽象.属性和方法分离,不是封装在一起的,复用性 ...

  8. hive 排序 order by sort by distribute by cluster by

    order by:     order by是全局排序,受hive.mapred.mode的影响.       使用orderby有一些限制:     1.在严格模式下(hive.mapred.mod ...

  9. zookeeper应用 - leader选举 锁

    模拟leader选举: 1.zookeeper服务器上有一个/leader节点 2.在/leader节点下创建短暂顺序节点/leader/lock-xxxxxxx 3.获取/leader的所有子节点并 ...

  10. HBase 负载均衡

    HBase 可以根据当前集群的负载以region为单位进行rebalance.在HMaster中,后台会起一个线程定期检查是否需要进行rebalance,线程叫做BalancerChore.线程每隔  ...