I have a list [1,2,4,7,5,2]
where I want to get rid of the commas to make it [1 2 4 7 5 2]
how would I go about this?
np.random.randint(0,4,12) will print out like [0 3 4 1 3 4 2 1 2 4 3 4]
and thats the kind of thing I want :)
You could do this:
out = '[' + ' '.join(str(item) for item in numbers)+ ']'
print out
In [7]: data = [1,2,4,7,5,2]
In [11]: '[{}]'.format(' '.join(map(str, data)))
Out[11]: '[1 2 4 7 5 2]'
or,
In [14]: str(data).replace(',','')
Out[14]: '[1 2 4 7 5 2]'
如果要使用numpy ndarray,请使用:
np.array([1, 2, 4, 7, 5, 2])
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.