numpy 函数一:linspace
生活随笔
收集整理的這篇文章主要介紹了
numpy 函数一:linspace
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
接觸 numpy 遇到的第一個函數可能就是 linspace 函數,但是對于我們這種沒有學過 matlab 的人來說,根本不知道這是什么。
所以只能自己查資料。
詞典顯示:
那么怎么用呢?
linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None)Return evenly spaced numbers over a specified interval.Returns `num` evenly spaced samples, calculated over theinterval [`start`, `stop` ].The endpoint of the interval can optionally be excluded.Parameters----------start : scalarThe starting value of the sequence.樣本起始值stop : scalarThe 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 stepsize changes when `endpoint` is False.num : int, optional樣本個數Number of samples to generate. Default is 50.endpoint : bool, optionalIf True, `stop` is the last sample. Otherwise, it is not included.Default is True.如果為真,則最后一個值(stop對應的值)包含在樣本中retstep : bool, optionalIf True, return (`samples`, `step`), where `step` is the spacingbetween samples.如果為真,返回樣本及步長dtype : dtype, optionalThe type of the output array. If `dtype` is not given, infer the datatype from the other input arguments.樣本的數據類型.. versionadded:: 1.9.0Returns-------samples : ndarrayThere 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 : floatOnly returned if `retstep` is TrueSize of spacing between samples.See Also--------arange : Similar to `linspace`, but uses a step size (instead of thenumber of samples).logspace : Samples uniformly distributed in log space.例:
import numpy as np import scipy as sp import pylab as pl# 從0到4pi之間,取100個樣點 x = np.linspace(0,4*np.pi,100)pl.plot(x,np.sin(x)) pl.show()結果:
轉載于:https://www.cnblogs.com/tk091/p/4520986.html
總結
以上是生活随笔為你收集整理的numpy 函数一:linspace的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: hdoj - 1258 Sum It U
- 下一篇: 「日常训练」 Genghis Khan