[Numpy-discussion] array 2 string

Michael S. Gilbert michael.s.gilbert@gmail....
Tue Mar 10 11:33:12 CDT 2009


On Tue, 10 Mar 2009 17:21:23 +0100, Mark Bakker wrote:
> Hello,
> 
> I want to convert an array to a string.
> 
> I like array2string, but it puts these annoying square brackets around
> the array, like
> 
> [[1 2 3],
>  [3 4 5]]
> 
> Anyway we can suppress the square brackets and get (this is what is
> written with savetxt, but I cannot get it to store in a variable)
> 1 2 3
> 4 5 6

This isn't pretty, but:

out = ''
for i in range( 0 , 2 ):
    for j in range( 0, 3 ):
        out += str( A[i,j] ) + ' '
    out += '\n'
print out


More information about the Numpy-discussion mailing list