1
我正在使用以下循環遍歷numpy數組並打印到單獨的文本文件中。如何從打印[1,2,3]打印到文本文件中的Python 1,2,3 Python
c= np.array([1, 2, 3])
nc = c.astype(np.int)
for x in nc:
print >> thing_here, x
但當我打開thing_here文本文件,其打印我的數組爲[1, 2, 3]
,而不是1, 2, 3
我怎樣才能擺脫[]的嗎?
'print >> thing_here,repr(x)[1:-1]'。 –
'','.join(map(str,x))',但可能是直接使用'csv.writer'更好嗎? – myaut
@ChristianDean導致它打印爲rray([1,2,3]) – cryptofish