Vincenzooo Vincenzooo -4 years ago 197
Python Question

Printing array of strings without delimiters (brackets, quotes and commas)

Despite this seeming an easy task, I didn't find a satisfying way of doing it.
There are several solutions based on map or try/except but none of these seems to me solid enough (e.g. working in a general case and with 2D arrays).

This can be done with pandas, but I would like to avoid importing an entire library just for this task, is it possible to do it just with numpy functions?

To make an example of what I mean, from an array like:

>>a=np.vstack([['zero','one'],np.array(np.arange(2)).T]).astype('|S')

>>print a
[['zero' 'one']
['0' '1']]


the desired output is:

zero one
0 1

Answer Source

You can use a list comprehension within str.join():

>>> print '\n'.join([' '.join(i) for i in a])
zero one
0 1
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download