[Numpy-discussion] printing array in tabular form
Jonathan Slavin
jslavin at cfa.harvard.edu
Fri May 10 08:45:01 EDT 2013
Sudheer,
This is not really numpy specific. There are many options for output
formatting in python. For the specific question you have, you could do:
print '{0}{1:8.3f}{2:8.3f}{3:8.3f}{4:8.3f}{5:8.3f}'.format(s,x1,x2,x3,x4,x5)
format is a built-in python string method (see python docs). The one
thing that I will agree with you on is that, as far as I know, there is
no repeat count mechanism. There are tricky ways around that, e.g.
fmt = '{0}' + ''.join(['{'+str(i)+':8.3f}' for i in range(1,6)])
print fmt.format(s,x1,x2,x3,x4,x5)
though not as simple as the fortran output statement.
Jon
On Fri, 2013-05-10 at 17:14 +0800, Sudheer Joseph wrote:
> Thank you,
> But I was looking for a format statement likw
> write(*,"(A,5F8.3)")
> 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: Daπid <davidmenhur at gmail.com>
> To: Discussion of Numerical Python
> <numpy-discussion at scipy.org>
> Sent: Thursday, 9 May 2013 2:29 PM
> Subject: Re: [Numpy-discussion] printing array in tabular form
>
>
> On 9 May 2013 10:06, Sudheer Joseph <sudheer.joseph at yahoo.com>
> wrote:
> > However writing a formatted out put looks to be bit tricky
> with python
> > relative to other programing languages.
>
> If performance is not an issue, you could do it by hand, as
> you can
> always do in any programming language:
>
>
> savefile = open('data.txt', 'w')
> N = len(IL)
>
> for start in xrange(N/5):
> if start+5 > N:
> end = N
> else:
> end = start+5
> print >> savefile, IL[start : end]
>
>
> But this is actually more verbose, and once you get into NumPy
> workflow, it is actually simple.
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion at scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
>
>
--
______________________________________________________________
Jonathan D. Slavin Harvard-Smithsonian CfA
jslavin at cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981 Cambridge, MA 02138-1516
cell: (781) 363-0035 USA
______________________________________________________________
More information about the NumPy-Discussion
mailing list