Search code examples
pythonnumpyformattingnumpy-ndarray

How to print a Numpy array without brackets?


I want to convert a = [1,2,3,4,5] into a_string = "1 2 3 4 5". The real numpy array is quite big (50000x200) so I assume using for loops is too slow.


Solution

  • You can use the join method from string:

    >>> a = [1,2,3,4,5]
    >>> ' '.join(map(str, a))
    "1 2 3 4 5"