Converting int arrays to string arrays in numpy without truncation

前端 未结 5 1482
野的像风
野的像风 2020-12-08 02:31

Trying to convert int arrays to string arrays in numpy

In [66]: a=array([0,33,4444522])
In [67]: a.astype(str)
Out[67]: 
array([\'0\', \'3\', \'4\'], 
               


        
5条回答
  •  北海茫月
    2020-12-08 03:19

    You can stay in numpy, doing

    np.char.mod('%d', a)
    

    This is twice faster than map or list comprehensions for 10 elements, four times faster for 100. This and other string operations are documented here.

提交回复
热议问题