python range中的步长必须是整数 numpy则可以是小数

>>> for ii in range(1,10,0.1):
print(ii)

Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
for ii in range(1,10,0.1):
TypeError: 'float' object cannot be interpreted as an integer
>>>

import numpy as np
arr=np.arange(0,10,1)
arr1=np.arange(0,1,0.1)

array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
array([0. , 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9])

 

posted @ 2023-09-27 10:11  myrj  阅读(82)  评论(0编辑  收藏  举报