将numpy字符串数组转换为.txt文件



我需要转换一个numpy数组:

array(['#fear.', 'Getting so angry.',
'Change your mind.', ..., 'birthday boy.',
'Living in the desert.'],
dtype='<U234')

在一个.txt文件中,我有点纠结于如何使用numpy数组,有什么提示吗?谢谢

我想要实现的是一个大的.txt文件,其中所有的字符串都在一起,就像这样:

'#fear, Getting so angry, Change your mind, birthday boy, Living in the desert'

句子不需要用逗号分隔

你可以试试这个:

import numpy as np
arr = np.array(['#fear.', 'Getting so angry.',
'Change your mind.', ..., 'birthday boy.',
'Living in the desert.'],
dtype='<U234')
with open('test.txt' ,"w") as file:
for e in arr:
file.write(e)

最新更新