程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

Differences between range, rangeand linspace in Python

編輯:Python

The same thing

range() and arange() Functions can be used to generate equal interval ( Isochromatic ) Sequence , Can be used to iterate .
Both function prototypes have three parameters :
range([start,] stop, [step])
arange([start,] stop, [step])
linspace(start, stop, num, endpoint=True, retstep=False, dtype=None)

start: Optional parameters , Indicates the starting value , The default is 0, The result contains the starting value
stop: Required parameters , Indicates the end value , The result does not contain an end value
step: Optional parameters , Represents the step value , The default is 1

difference :

range() yes python The built-in function of ;
arange() yes numpy Functions in modules , When using, you need to import numpy modular .

range() Decimal step size is not supported , and np.arange() Support step size step Is a decimal

range() The return result of is list object
arange() The return result of is ndarray object .

inspace() By specifying the starting value 、 The final value and the number of elements create a one-dimensional array representing an arithmetic sequence , Can pass endpoint Parameter specifies whether to include a final value , The default value is True, namely Include final value .

range and numpy.arange It's all based on the starting value 、 Termination value 、 The step size is a parameter , and linspase With the starting value 、 Termination value 、 The number of elements is a parameter .


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved