如何使用最近邻算法将数组输出 [0 0 0] 转换为 Python 中的 [0, 0, 0]?

How to convert array output [0 0 0] to [0, 0, 0] in Python with Nearest Neighbour Algorithm?

我有一个 Ubuntu 14.04 32 位虚拟机并使用默认的 Python 2.7。我有一个最近邻脚本如下:

import numpy as np
from sklearn.neighbors import NearestNeighbors

X = np.array([[28273, 20866, 29961, 27190, 31790, 19714, 8643, 14482, 5384],
[12343, 45634, 29961, 27130, 33790, 14714, 7633, 15483, 4484]])

knn = NearestNeighbors(algorithm='auto', leaf_size=30, n_neighbors=5, p=2, 
radius=1.0, warn_on_equidistant=True).fit(X)

distance, indices = knn.kneighbors(X[0])
print(indices)

当脚本成功运行时,我也得到了输出 - [[0 1]](或类似的东西)
问题是没有任何逗号分隔数组中的每个元素。我在网上看到过类似的代码,其他代码的输出类似于 - array([[0, 1]])[[0, 1]]
我试过 print(', '.join(indices)) 但它抛出错误 -
print(', '.join(indices)) TypeError: sequence item 0: expected string, numpy.ndarray found
如何修改脚本以获得与上述类似的输出? ([0, 1])
预先感谢您的帮助:)

将其转换为列表

list(indices)

尝试,

print indices
>>>[[0 1]]
print list(indices)
>>>[array([0, 1])]
print indices.tolist()
>>>[[0, 1]]

print (indices)

(prints [0 1])

b = list(indices)

print b

(prints [0,1])