[Numpy-discussion] printing array in tabular form
Derek Homeier
derek at astro.physik.uni-goettingen.de
Tue May 7 09:11:19 EDT 2013
Dear Sudheer,
On 07.05.2013, at 11:14AM, Sudheer Joseph <sudheer.joseph at yahoo.com> wrote:
> I need to print few arrays in a tabular form for example below array IL has 25 elements, is there an easy way to print this as 5x5 comma separated table? in python
>
> IL=[]
> for i in np.arange(1,bno+1):
> IL.append(i)
> print(IL)
>
assuming you want this table printed to a file, savetxt does just what you need. In brief for your case,
np.savetxt("file.txt", IL.reshape(-1,5), fmt='%5d', delimiter=',')
should print it in the requested form; you can refer to the save txt documentation for further options.
HTH,
Derek
More information about the NumPy-Discussion
mailing list