Re: [Numpy-discussion] printing array in tabular form

2013-05-11 Thread Sudheer Joseph
Thank you very much,
  These tips with some effort from me should do it for me.
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.in...@gmail.com;sudheer.jos...@yahoo.com
Web- http://oppamthadathil.tripod.com
***


- Original Message -
 From: Henry Gomersall h...@cantab.net
 To: Discussion of Numerical Python numpy-discussion@scipy.org
 Cc: 
 Sent: Friday, 10 May 2013 5:29 PM
 Subject: Re: [Numpy-discussion] printing array in tabular form
 
 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
 
 How about the following:
 
 print('IL = ' + (('%d,' * 5)[:-1] + '\n     ') * 5 % 
 tuple(IL))
 
 If instead of a list IL you had some arbitrary 2D array, a, you could do
 (with 2 lines for clarity):
 
 print_string = 'a  = ' + (('%d,' * a.shape[1])[:-1] + 
 '\n     ') *
                           a.shape[0] % tuple(a.T.ravel())
 print(print_string)
 
 I'll leave it as an exercise for you to put that into a file.
 
 hen
 
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
 
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-11 Thread Sudheer Joseph
Thank you Very much,
 This will help me a lot.
with best regards,
Sudheer


 - Original Message -

 From: Derek Homeier de...@astro.physik.uni-goettingen.de
 To: Discussion of Numerical Python numpy-discussion@scipy.org
 Cc: 
 Sent: Friday, 10 May 2013 6:10 PM
 Subject: Re: [Numpy-discussion] printing array in tabular form
 
 On 10.05.2013, at 1:20PM, Sudheer Joseph sudheer.jos...@yahoo.com wrote:
 
  If some one has a quick way I would like to learn from them or get a 
 referecence 
  where the formatting part is described which was 
  my intention while posting here. As I have been using fortran I just tried 
  to use it to explain my requirement
 
 Admittedly the formatting options in Python can be confusing to beginners, 
 precisely
 since they are much more powerful than for many other languages. As already 
 pointed
 out, formats of the type '(5i5)' are very common to Fortran programs and 
 thus readily
 supported by the language. np.savetxt is just a convenience function to 
 support 
 a number
 of similarly common output types, and it can create csv, tab-separated, or 
 plenty of other
 outputs from a numpy array just out of the box. 
 But you added to the confusion as you did not make it clear that you were not 
 just requiring
 a plain csv file as your Fortran example would create (and the first version 
 did 
 not even
 have the commas); since this is a rather non-standard form you will just have 
 to 
 write a
 short loop yourself, wether you are using Fortran or Python.
 
                           Infact the program which should read this file 
 requires it in specified format which should look like
  IL = 1,2,3,4,5
       1,2,3,4,5
       1,2,3,4,5
 
 The formats are all documented 
 http://docs.python.org/2/library/string.html#format-specification-mini-language
 one important thing to know is that you can pretty much add (i.e. 
 concatenate) 
 them like strings:
 
 print((%6s+4*%d,+%d\n) % ((IL = 
 ,)+tuple(IL[:5])))
 
 or, perhaps a bit clearer:
 
 fmt = %6s+4*%d,+%d\n
 print_t = (IL = ,)+tuple(IL[:5])
 print(fmt % print_t)
 
 The other important bit to keep in mind is that all arguments have to be 
 passed 
 as tuples.
 This should allow you to write a loop to print with a header or an 
 empty header column
 for the subsequent lines as you see fit. 
 Except for the string field which is explicitly formatted %s here, 
 this is mostly equivalent
 to the example Henry just posted.
 
 HTH,
                     Derek
 
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
 
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-11 Thread Sudheer Joseph
Thank youNicolodi,
    I hope I did not hurt you by my little fight.!!
with best regards,
Sudheer

 

- Original Message -
 From: Daniele Nicolodi dani...@grinta.net
 To: numpy-discussion@scipy.org
 Cc: 
 Sent: Friday, 10 May 2013 6:21 PM
 Subject: Re: [Numpy-discussion] printing array in tabular form
 
 On 10/05/2013 13:20, Sudheer Joseph wrote:
 
  Hi,
  I am trying to learn Python after feeling its utility in coding and
  also reading a bit aboutits potential only, please do not put words
  in to my mouth like below.
 
 I didn't put words in your mouth, I simply quoted emails you sent to the
 list and gave my interpretation of what you wrote.
 
  Before denigrating a programming language
 
  If some one has a quick way I would like to learn from them or get a 
 referecence 
  where the formatting part is described which was 
  my intention while posting here. As I have been using fortran I just tried 
  to use it to explain my requirement
 
 For references about string formatting in Python:
 
 http://docs.python.org/2/library/string.html#formatstrings
 http://docs.python.org/2/library/stdtypes.html#string-formatting
 
 for the numpy array to text formatting:
 
 http://docs.scipy.org/doc/numpy/reference/generated/numpy.savetxt.html
 
 writing a function to do what you ask is trivial. Unfortunately there is
 no format the thing as I wish function.
 
 If you wish to format numpy arrays preceding them with a variable name,
 the following is a possible solution that gives the same formatting as
 in your example:
 
 import numpy as np
 import sys
 
 def format(out, v, name):
     header = {} = .format(name)
     out.write(header)
     np.savetxt(out, v, fmt=%d, delimiter=, ,
                newline=\n +   * len(header))
     out.write(\n)
 
 IL = np.array([range(5), ] * 5)
 format(sys.stdout, IL, IL)
 
 
 Cheers,
 Daniele
 
 ___
 NumPy-Discussion mailing list
 NumPy-Discussion@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
 
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-10 Thread Sudheer Joseph
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.in...@gmail.com;sudheer.jos...@yahoo.com
Web- http://oppamthadathil.tripod.com
***



 From: Daπid davidmen...@gmail.com
To: Discussion of Numerical Python numpy-discussion@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.jos...@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@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-10 Thread Daniele Nicolodi
On 10/05/2013 11:14, Sudheer Joseph wrote:

 However writing a formatted out put looks to be bit tricky with
 python relative to other programing languages.

...

 I was looking for a format statement likw write(*,(A,5F8.3))

Before denigrating a programming language I would make sure to have a
basic understanding of it.  Every language is going to be tricky if you
approach it with the mindset of Fortran programming.

The output format you are trying to obtain is easy in forrtran because
it is how the default text output formatting is designed.  Of course
obtaining it with a different programming language / numerical library
takes some more effort. But is not tricky at all.


Cheers,
Daniele

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-10 Thread Sudheer Joseph


Hi,
   I am trying to learn Python after feeling its utility in coding  and also 
reading a bit about 
its potential only, please do not put words in to my mouth like below.


 Before denigrating a programming language

If some one has a quick way I would like to learn from them or get a 
referecence 
where the formatting part is described which was 
my intention while posting here. As I have been using fortran I just tried 
to use it to explain my requirement

with best regards,
Sduheer

From: Daniele Nicolodi dani...@grinta.net

To: numpy-discussion@scipy.org 
Sent: Friday, 10 May 2013 3:12 PM
Subject: Re: [Numpy-discussion] printing array in tabular form
 

On 10/05/2013 11:14, Sudheer Joseph wrote:

 However writing a formatted out put looks to be bit tricky with
 python relative to other programing languages.

...

 I was looking for a format statement likw write(*,(A,5F8.3))

Before denigrating a programming language I would make sure to have a
basic understanding of it.  Every language is going to be tricky if you
approach it with the mindset of Fortran programming.

The output format you are trying to obtain is easy in forrtran because
it is how the default text output formatting is designed.  Of course
obtaining it with a different programming language / numerical library
takes some more effort. But is not tricky at all.


Cheers,
Daniele

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion



___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-10 Thread Derek Homeier
On 10.05.2013, at 1:20PM, Sudheer Joseph sudheer.jos...@yahoo.com wrote:

 If some one has a quick way I would like to learn from them or get a 
 referecence 
 where the formatting part is described which was 
 my intention while posting here. As I have been using fortran I just tried 
 to use it to explain my requirement
 
Admittedly the formatting options in Python can be confusing to beginners, 
precisely
since they are much more powerful than for many other languages. As already 
pointed
out, formats of the type '(5i5)' are very common to Fortran programs and thus 
readily
supported by the language. np.savetxt is just a convenience function to support 
a number
of similarly common output types, and it can create csv, tab-separated, or 
plenty of other
outputs from a numpy array just out of the box. 
But you added to the confusion as you did not make it clear that you were not 
just requiring
a plain csv file as your Fortran example would create (and the first version 
did not even
have the commas); since this is a rather non-standard form you will just have 
to write a
short loop yourself, wether you are using Fortran or Python.

  Infact the program which should read this file 
 requires it in specified format which should look like
 IL = 1,2,3,4,5
  1,2,3,4,5
  1,2,3,4,5
 
The formats are all documented 
http://docs.python.org/2/library/string.html#format-specification-mini-language
one important thing to know is that you can pretty much add (i.e. concatenate) 
them like strings:

print((%6s+4*%d,+%d\n) % ((IL = ,)+tuple(IL[:5])))

or, perhaps a bit clearer:

fmt = %6s+4*%d,+%d\n
print_t = (IL = ,)+tuple(IL[:5])
print(fmt % print_t)

The other important bit to keep in mind is that all arguments have to be passed 
as tuples.
This should allow you to write a loop to print with a header or an empty 
header column
for the subsequent lines as you see fit. 
Except for the string field which is explicitly formatted %s here, this is 
mostly equivalent
to the example Henry just posted.

HTH,
Derek

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-10 Thread Jonathan Slavin
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.in...@gmail.com;sudheer.jos...@yahoo.com
 Web- http://oppamthadathil.tripod.com
 ***
 
 __
 From: Daπid davidmen...@gmail.com
 To: Discussion of Numerical Python
 numpy-discussion@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.jos...@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@scipy.org
 http://mail.scipy.org/mailman/listinfo/numpy-discussion
 
 
 

-- 
__
Jonathan D. Slavin  Harvard-Smithsonian CfA
jsla...@cfa.harvard.edu 60 Garden Street, MS 83
phone: (617) 496-7981   Cambridge, MA 02138-1516
 cell: (781) 363-0035   USA
__

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-10 Thread Daniele Nicolodi
On 10/05/2013 13:20, Sudheer Joseph wrote:

 Hi,
 I am trying to learn Python after feeling its utility in coding and
 also reading a bit aboutits potential only, please do not put words
 in to my mouth like below.

I didn't put words in your mouth, I simply quoted emails you sent to the
list and gave my interpretation of what you wrote.

 Before denigrating a programming language
 
 If some one has a quick way I would like to learn from them or get a 
 referecence 
 where the formatting part is described which was 
 my intention while posting here. As I have been using fortran I just tried 
 to use it to explain my requirement

For references about string formatting in Python:

http://docs.python.org/2/library/string.html#formatstrings
http://docs.python.org/2/library/stdtypes.html#string-formatting

for the numpy array to text formatting:

http://docs.scipy.org/doc/numpy/reference/generated/numpy.savetxt.html

writing a function to do what you ask is trivial. Unfortunately there is
no format the thing as I wish function.

If you wish to format numpy arrays preceding them with a variable name,
the following is a possible solution that gives the same formatting as
in your example:

import numpy as np
import sys

def format(out, v, name):
header = {} = .format(name)
out.write(header)
np.savetxt(out, v, fmt=%d, delimiter=, ,
   newline=\n +   * len(header))
out.write(\n)

IL = np.array([range(5), ] * 5)
format(sys.stdout, IL, IL)


Cheers,
Daniele

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-10 Thread Derek Homeier
On 10.05.2013, at 2:51PM, Daniele Nicolodi dani...@grinta.net wrote:

 If you wish to format numpy arrays preceding them with a variable name,
 the following is a possible solution that gives the same formatting as
 in your example:
 
 import numpy as np
 import sys
 
 def format(out, v, name):
header = {} = .format(name)
out.write(header)
np.savetxt(out, v, fmt=%d, delimiter=, ,
   newline=\n +   * len(header))
out.write(\n)
 
 IL = np.array([range(5), ] * 5)
 format(sys.stdout, IL, IL)

That is a quite ingenuous way to use savetxt functionality to write that extra 
column!

Only two comments:

Don't call that function format, as it would mask the 'format' builtin!

In the present version it will only work with a file handle; to print it a to 
file you would need
to pass it as fformat(open(fname, 'a'), … or check for that case inside the 
function.

Cheers,
Derek
 


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-09 Thread Sudheer Joseph
Thank you Gomersall,
  However writing a formatted out put looks to be bit tricky with 
python relative to other programing languages.
For example,
 If I wanted to print below text in a file (for reading by another 
program), it looks to be not an easy jobHope new developments will come and 
a userfriendly formatted out put method for pyton will evolve.


IL= 1,2,3,4,5
    5,5,6,8,0

JL= 1,2,3,4,5
    5,5,6,8,0 

KL= 1,2,3,4,5
    5,5,6,8,0

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.in...@gmail.com;sudheer.jos...@yahoo.com
Web- http://oppamthadathil.tripod.com
***



 From: Henry Gomersall h...@cantab.net
To: Discussion of Numerical Python numpy-discussion@scipy.org 
Sent: Wednesday, 8 May 2013 12:23 PM
Subject: Re: [Numpy-discussion] printing array in tabular form
 

On Wed, 2013-05-08 at 10:13 +0800, Sudheer Joseph wrote:
 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'

IL is a list, not a numpy array. You can either convert the list to an
array after you've filled it, using np.array(IL), or you can
pre-allocate the array and fill it directly in the loop.

Cheers,

Henry

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-09 Thread Daπid
On 9 May 2013 10:06, Sudheer Joseph sudheer.jos...@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@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-09 Thread Henry Gomersall
On Thu, 2013-05-09 at 16:06 +0800, Sudheer Joseph wrote:
 If I wanted to print below text in a file (for reading by another
 program), it looks to be not an easy jobHope new developments will
 come and a userfriendly formatted out put method for pyton will
 evolve.

I don't understand what the problem is - this seems to be trivial to
solve. You gave an example in Fortran; Is the transliteration to Python
not acceptable?

Is the output format specified by the receiving program? If not, there
are loads of options for creating interoperable text files.

Henry

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-09 Thread Chris Barker - NOAA Federal
On Thu, May 9, 2013 at 1:06 AM, Sudheer Joseph sudheer.jos...@yahoo.comwrote:

 Thank you Gomersall,
   However writing a formatted out put looks to be bit tricky with
 python relative to other programing languages.


this is just plain wrong -- working with text in python is as easy, or
easier, than most languages.

Take a little time to learn a bit of pyton, and a bit of numpy, then come
back if you can't figure it out.

But as a rule -- if it's seems hard and/or awkward, you are probably doing
it wrong!

 -Chris
-- 

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/ORR(206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115   (206) 526-6317   main reception

chris.bar...@noaa.gov
___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-08 Thread Henry Gomersall
On Wed, 2013-05-08 at 10:13 +0800, Sudheer Joseph wrote:
 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'

IL is a list, not a numpy array. You can either convert the list to an
array after you've filled it, using np.array(IL), or you can
pre-allocate the array and fill it directly in the loop.

Cheers,

Henry

___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


[Numpy-discussion] printing array in tabular form

2013-05-07 Thread Sudheer Joseph
Dear experts,
    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)

%
in fortran I could do it as below
%
integer matrix(5,5)
   in=0
  do, k=1,5
  do, l=1,5
   in=in+1
  matrix(k,l)=in
  enddo
  enddo
  m=5
  n=5
  do, i=1,m
  write(*,(5i5)) ( matrix(i,j), j=1,n )
  enddo
  end
 

***
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.in...@gmail.com;sudheer.jos...@yahoo.com
Web- http://oppamthadathil.tripod.com
***___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-07 Thread Derek Homeier
Dear Sudheer,

On 07.05.2013, at 11:14AM, Sudheer Joseph sudheer.jos...@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@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


Re: [Numpy-discussion] printing array in tabular form

2013-05-07 Thread Sudheer Joseph
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.in...@gmail.com;sudheer.jos...@yahoo.com
Web- http://oppamthadathil.tripod.com
***



 From: Derek Homeier de...@astro.physik.uni-goettingen.de
To: Discussion of Numerical Python numpy-discussion@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.jos...@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@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion


___
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion