[SciPy-user] Input value from data file to 2D array
tournesol
tournesol33@gmail....
Thu Apr 17 22:14:25 CDT 2008
Hi All.
I'm a newbie of python and scipy, numpy and
try to rewriting the Fortran77 code to Python.
First, here is my Fortran code.
DIMENSION A(10,10), B(10,10)
OPEN(21,FILE='aaa.dat')
DO 10 K=1,2
READ(21,1602) ((A(I,J),J=1,3),I=1,2)
READ(21,1602) ((B(I,J),J=1,3),I=1,2)
10 CONTINUE
WRITE(6,1602) ((A(I,J),J=1,3),I=1,2)
WRITE(6,1602) ((B(I,J),J=1,3),I=1,2)
1602 FORMAT(3I4)
END
and aaa.dat file is
0 1 1
1 1 1
2 1 1
; ; ;
; ; ;
18 1 1
19 1 1
The code is going to read each value of the data file(aaa.dat)
and input the value to the array A, B. According the "DO 10 K=1,2"
which means a loop of Fortran it is going to try to read 1st 2x3 array
and set them to A, also read 2nd 2x3 array to B.
Two "WRITE(6,1602) "s mean that the final value of array A and B are
3rd 2x3 array adn 4th 2x3 array
4 1 1
5 1 1
6 1 1
7 1 1
Question 1: How to input value from data file to 2D array ?
Can I write code like following ?
a=zeros([2,3], Float)
for i in range(1,2):
for j in range(1,3):
a[i][j]=i,j
(If the size of data file is very big , using
read_array() or fromfile() will be very hard. )
Question 2: Such like "DO 10 K=1,1500", I just read a part of
data file(<=very big file). How cat write this with Python ?
Any advice please!
More information about the SciPy-user
mailing list