Python 2.7 linspace()生成浮点值,但int是必需的

Python 2.7 linspace()生成浮点值,但int是必需的,python-2.7,dictionary,Python 2.7,Dictionary,我正在生成x轴值(时间从1到23)和v轴值(客户数量)。我想把这两个列表作为字典连接起来,这已经完成了,但是我在使用linspace()生成时得到了x的浮点值 输出为 {1.0:12,2.0:11,3.0:3,4.0:19,5.0:12,6.0:12,7.0:5,8.0:13,9.0:15,10.0:3,11.0:15,12.0:20,13.0:5,14.0:3,15.0:18,16.0:12,17.0:5,18.0:6,19.0:8,20.0:16,21.0:19,22.0:1,23.0:16

我正在生成x轴值(时间从1到23)和v轴值(客户数量)。我想把这两个列表作为字典连接起来,这已经完成了,但是我在使用
linspace()
生成时得到了x的浮点值

输出为

{1.0:12,2.0:11,3.0:3,4.0:19,5.0:12,6.0:12,7.0:5,8.0:13,9.0:15,10.0:3,11.0:15,12.0:20,13.0:5,14.0:3,15.0:18,16.0:12,17.0:5,18.0:6,19.0:8,20.0:16,21.0:19,22.0:1,23.0:16}


如何将1.0转换为1等等。我尝试了
int(time\u vlaues)
,但没有成功

尝试将numpy浮点数组转换为int数组的类型方法:

time_values = np.linspace(1,23,23) # print from 1,2...23
number_of_clients = [] # create empty list that will hold number of clients
for i in range(1,24,1):
    rand_value =  random.randint(1,20) # generate number of clients
    number_of_clients.append(rand_value)


data = dict(zip(time_values.astype(int),number_of_clients))
print(data)

输出:

{1: 17, 2: 6, 3: 8, 4: 3, 5: 12, 6: 11, 7: 18, 8: 1, 9: 8, 10: 1, 11: 17, 12: 2, 13: 5, 14: 6, 15: 1, 16: 8, 17: 19, 18: 2, 19: 13, 20: 15, 21: 16, 22: 17, 23: 14}

尝试astype方法将numpy浮点数组转换为int数组:

time_values = np.linspace(1,23,23) # print from 1,2...23
number_of_clients = [] # create empty list that will hold number of clients
for i in range(1,24,1):
    rand_value =  random.randint(1,20) # generate number of clients
    number_of_clients.append(rand_value)


data = dict(zip(time_values.astype(int),number_of_clients))
print(data)

输出:

{1: 17, 2: 6, 3: 8, 4: 3, 5: 12, 6: 11, 7: 18, 8: 1, 9: 8, 10: 1, 11: 17, 12: 2, 13: 5, 14: 6, 15: 1, 16: 8, 17: 19, 18: 2, 19: 13, 20: 15, 21: 16, 22: 17, 23: 14}