具有以下描述我的垃圾箱边缘的nparray,如下所示:
np.arange(min_value , max_value + 1, bin_size)
[ -1 35 71 107 143 179 215 251 287 323 359]
我想像这样创建字符串标签数组:
['0-36','36-72','72-108','108-144','144-180','180-216','216-252','252-288','288-324','324-360']
怎么做呢?
答案 0 :(得分:4)
将列表理解与f-string
一起使用:
b = [f'{i+1}-{j+1}' for i, j in zip(a[:-1], a[1:])]
print (b)
['0-36', '36-72', '72-108', '108-144', '144-180',
'180-216', '216-252', '252-288', '288-324', '324-360']
a += 1
b = [f'{i}-{j}' for i, j in zip(a[:-1], a[1:])]