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.
To print a NumPy array without enclosing square brackets, the most Pythonic way is to unpack all array values into the print() function and use the sep=', ' argument to separate the array elements with a comma and a space.
use asterisk '*' operator to print a list without square brackets.
Using strip() to Remove Brackets from the Beginning and End of Strings in Python. If your brackets are on the beginning and end of your string, you can also use the strip() function. The Python strip() function removes specified characters from the beginning and end of a string.
You can use the join
method from string:
>>> a = [1,2,3,4,5] >>> ' '.join(map(str, a)) "1 2 3 4 5"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With