Fastest way to generate delimited string from 1d numpy array

前端 未结 7 2208
春和景丽
春和景丽 2020-12-15 16:53

I have a program which needs to turn many large one-dimensional numpy arrays of floats into delimited strings. I am finding this operation quite slow relative to the mathema

7条回答
  •  攒了一身酷
    2020-12-15 17:24

    ','.join(x.astype(str))
    

    is about 10% slower than as

    x_arrstr = np.char.mod('%f', x)
    x_str = ",".join(x_arrstr)
    

    but is more readable.

提交回复
热议问题