关于#numpy#的问题,如何解决?

numpy模块
在3.5公里的路段每隔0.7公里设置一路桩,创建路桩的位置数组。

import numpy as np
arr3=np.linspace(0,3.5,0.7)
print(arr3)

TypeError                                 Traceback (most recent call last)
~\AppData\Local\Temp\ipykernel_58568\2770250342.py in 
----> 1 arr3=np.linspace(0,3.5,0.7)
      2 print(arr3)

<__array_function__ internals> in linspace(*args, **kwargs)

D:\Anoconda3\lib\site-packages\numpy\core\function_base.py in linspace(start, stop, num, endpoint, retstep, dtype, axis)
    118 
    119     """
--> 120     num = operator.index(num)
    121     if num < 0:
    122         raise ValueError("Number of samples, %s, must be non-negative." % num)

TypeError: 'float' object cannot be interpreted as an integer

因为linspace方法的第三个参数表示要生成的个数,应该是一个整数,而你的是小数。所以报错。建议使用:
np.arange(0,3.6,0.7)
望采纳下。谢谢

np.linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0)
函数的意思是:在间隔start和stop之间返回num个均匀间隔的数据。结合你的需求:在3.5公里的路段每隔0.7公里设置一路桩,创建路桩的位置数组。那么应该是:

import numpy as np
arr3=np.linspace(0,3.5,5)
print(arr3)

有帮助的话,请点采纳~