I am trying to import some data (pressures, stresses) for a set of pre-defined x,y points from a file using genfromtxt. Where the data is just output as a long column split up by a header names, for example:
time
1.0022181PORE_PRE
-18438721.41
-18438721.41
........STRS_11
-28438721.41
-28438721.41
........
The time data is only one point, but the PORE_PRE and STRS_11 and other variables contain many but equal numbers of data points. I use the following code:
import numpy as np
import matplotlib.pyplot as plt
file1=open('Z:/EFNHigh_Res/data_tstep1.out','r')
time=np.genfromtxt(file1,names=None,dtype=None,autostrip=True)
With this code I get a structured array with all of the data in one column. I have managed to delete out the time, by deleting the first two rows.
My initial idea was to then reshape the array using information relating to the number of data points which I have found previously and the total number of data points in the column. For example:
xx=np.reshape(time3,307,4)
print xx
However I get the error below, and can't seem to find a way to reshape it, I am guessing it's not possible for some reason, due to the 1D type nature of the array.
File "Z:\EFNHigh_Res\plotting.py", line 39, in <module>
xx=np.reshape(time3,307,4)
File "C:\Python27\ArcGIS10.2\lib\site-packages\numpy\core\fromnumeric.py",line 171, in reshape
return reshape(newshape, order=order)
ValueError: total size of new array must be unchanged
I don't have much choice over the output format (other than a more complicated arrangement). It seems like it should be a simple operation, but I can't figure it out, but I am very new to python. I have also tried to view only floating point data using the following code, but I get an error as below, or a very large number of data points, greater than those contained within the array.
xx=time3.view(dtype=np.float)
ValueError: new type not compatible with array
Can anyone suggest how I could deal with reading the file in?