日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

【python】numpy库linspace相同间隔采样 详解

發布時間:2023/11/30 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【python】numpy库linspace相同间隔采样 详解 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

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.

當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

Graphical illustration:

轉載于:https://www.cnblogs.com/zhaolide/p/10026178.html

總結

以上是生活随笔為你收集整理的【python】numpy库linspace相同间隔采样 详解的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。