作者:namelessml
来源:CSDN
原文:https://blog.csdn.net/namelessml/article/details/52431570
版权声明:本文为博主原创文章,转载请附上博文链接!


range(start, end, step),返回一个list对象,起始值为start,终止值为end,但不含终止值,步长为step。只能创建int型list。
arange(start, end, step),与range()类似,但是返回一个array对象。需要引入import numpy as np,并且arange可以使用float型数据。

 1 >>> import numpy as np
 2 >>> range(1,10,2)
 3 [1, 3, 5, 7, 9]
 4 >>> np.arange(1,10,2)
 5 array([1, 3, 5, 7, 9])
 6 >>> range(1,5,0.5)
 7 Traceback (most recent call last):
 8   File "<stdin>", line 1, in <module>
 9 TypeError: range() integer step argument expected, got float.
10 >>> np.arange(1,5,0.5)
11 array([ 1. ,  1.5,  2. ,  2.5,  3. ,  3.5,  4. ,  4.5])

 

相关文章:

  • 2021-06-28
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-02-07
猜你喜欢
  • 2021-06-18
  • 2021-12-06
  • 2022-12-23
  • 2021-07-09
  • 2022-12-23
  • 2021-08-24
相关资源
相似解决方案