[Numpy-discussion] Read array from file
Lisandro Dalcin
dalcinl@gmail....
Fri Mar 14 17:42:07 CDT 2008
If you just want to manage VTK files, the you have to definitely try
pyvtk. http://cens.ioc.ee/projects/pyvtk/
I have a similar numpy-based but independent implementation, not fully
tested, targeted to only write VTK files for big datasets (let say,
more than 1 millon nodes) in eider ascii or bynary format. Never found
time for implementing reading.
On 3/14/08, Dimitrios Kiousis <dkiousis@gmail.com> wrote:
> Hello python users,
>
> I have an input file consisting of string-lines and float-lines. This is how
> it looks:
>
> # vtk DataFile Version 3.0
> VTK file exported from FEAP
> ASCII
> DATASET UNSTRUCTURED_GRID
> POINTS 6935 FLOAT
> 15.44261 12.05814 54.43124
> 15.54899 12.00075 53.85503
> 15.95802 11.92959 53.88939
> 15.84085 12.00235 54.43274
> 15.53889 11.16645 54.51649
> 15.57673 11.10806 53.96009
> 16.10059 11.06809 53.87672
> 16.04238 11.11615 54.47454
> 15.78142 11.82206 53.33932
> 16.13055 11.75515 53.37313
> .................
>
> I want to read the first 5 string lines, and then store the float data
> (coordinates) into an array.
> It took me some time to figure this out but this is the script with which I
> came out:
>
> # Read and write the first information lines
> for i in range(0,5):
> Fdif.write( Fpst.readline() )
>
> # Read and write coordinates
> # --------------------------
>
> # Initialization
> coords = zeros( (nnod,3), float )
>
> for i in range(0,nnod):
> # Read line
> x = Fref.readline() # Read lines
> x = x.split() # Split line to strings
> x = map ( float,x ) # Convert string elements to floats
> x = array ( x ) # Make an array
> for j in range (0,3):
> coords[i,j] = x[j]
>
> It seems quite complicated to me, but I haven't figure any nicer way. Could
> you tell me if what I am doing looks reasonanble or if there are any other
> solutions?
> Do I really need to initiallize coords?
>
> Thanks in advance,
> Dimitrios
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
>
>
--
Lisandro Dalcín
---------------
Centro Internacional de Métodos Computacionales en Ingeniería (CIMEC)
Instituto de Desarrollo Tecnológico para la Industria Química (INTEC)
Consejo Nacional de Investigaciones Científicas y Técnicas (CONICET)
PTLC - Güemes 3450, (3000) Santa Fe, Argentina
Tel/Fax: +54-(0)342-451.1594
More information about the Numpy-discussion
mailing list