Convert a numpy.ndarray to string(or bytes) and convert it back to numpy.ndarray

前端 未结 7 661
北恋
北恋 2020-12-08 09:52

I\'m having a little trouble here,

I\'m trying to convert a numpy.ndarray to string, I\'ve already done that like this:

randomArray.tostring()
         


        
7条回答
  •  误落风尘
    2020-12-08 10:17

    Imagine you have a numpy array of text like in a messenger

     >>> stex[40]
     array(['Know the famous thing ...
    

    and you want to get statistics from the corpus (text col=11) you first must get the values from dataframe (df5) and then join all records together in one single corpus:

     >>> stex = (df5.ix[0:,[11]]).values
     >>> a_str = ','.join(str(x) for x in stex)
     >>> a_str = a_str.split()
     >>> fd2 = nltk.FreqDist(a_str)
     >>> fd2.most_common(50)
    

提交回复
热议问题