How to convert array output [0 0 0] to [0, 0, 0] in Python with Nearest Neighbour Algorithm? -
i have ubuntu 14.04 32-bit vm , using default python 2.7. have nearest neighbour script follows:
import numpy np 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)
while script runs , output - [[0 1]]
(or similar)
issue there aren't commas separating each element in array. have seen similar code online , output of other code - array([[0, 1]])
or [[0, 1]]
have tried print(', '.join(indices))
throws error -
print(', '.join(indices)) typeerror: sequence item 0: expected string, numpy.ndarray found
how modify script such output similar 1 mentioned above? ([0, 1])
in advance :)
print (indices)
(prints [0 1])
b = list(indices)
print b
(prints [0,1])
Comments
Post a Comment