[Numpy-discussion] printing array in tabular form
Sudheer Joseph
sudheer.joseph at yahoo.com
Tue May 7 22:13:25 EDT 2013
Thank you Derek,
However I get below error. Please tell me if any thing I am missing.
file "read_reg_grd.py", line 22, in <module>
np.savetxt("file.txt", IL.reshape(-1,5), fmt='%5d', delimiter=',')
AttributeError: 'list' object has no attribute 'reshape'
with best regards,
Sudheer
***************************************************************
Sudheer Joseph
Indian National Centre for Ocean Information Services
Ministry of Earth Sciences, Govt. of India
POST BOX NO: 21, IDA Jeedeemetla P.O.
Via Pragathi Nagar,Kukatpally, Hyderabad; Pin:5000 55
Tel:+91-40-23886047(O),Fax:+91-40-23895011(O),
Tel:+91-40-23044600(R),Tel:+91-40-9440832534(Mobile)
E-mail:sjo.India at gmail.com;sudheer.joseph at yahoo.com
Web- http://oppamthadathil.tripod.com
***************************************************************
>________________________________
> From: Derek Homeier <derek at astro.physik.uni-goettingen.de>
>To: Discussion of Numerical Python <numpy-discussion at scipy.org>
>Sent: Tuesday, 7 May 2013 6:41 PM
>Subject: Re: [Numpy-discussion] printing array in tabular form
>
>
>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
>
>_______________________________________________
>NumPy-Discussion mailing list
>NumPy-Discussion at scipy.org
>http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20130508/d9fff5ab/attachment.html>
More information about the NumPy-Discussion
mailing list