Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 854
Framester Avatar asked Feb 20 '12 11:02

Framester


People also ask

How do I print an array without NumPy brackets?

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.

How do you print without brackets in Python?

use asterisk '*' operator to print a list without square brackets.

How do you remove square brackets from an array in Python?

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.


1 Answers

You can use the join method from string:

>>> a = [1,2,3,4,5] >>> ' '.join(map(str, a)) "1 2 3 4 5" 
like image 166
tito Avatar answered Oct 06 '22 04:10

tito