[SciPy-user] Generating a 4D array from a set of 3D arrays

Dharhas Pothina Dharhas.Pothina@twdb.state.tx...
Wed May 21 12:05:35 CDT 2008


I'm trying to read 3 dimensional time series data from a file and store it in a numpy array so I can analyze the data. I'm having problems working out how to append the 3D array from each timestep to make a 4D array. I worked out that I could make a list of 3D arrays but if I do that I'm having issues slicing it the way I need to.

My final need is an array data_array[time,level,node,var] that I can slice by saying data_array[:,1,23,1] to get a time history at level=1,node=23,var=1 etc or I need to know how to slice a list (data_list[:][1,23,1] gives an error)

i.e :

a = array([[[  1,   2],[  3,   4],[  5,   6]],[[101, 102],[103, 104],[105, 106]],[[201, 202],[203, 204],[205, 206]]])
newdata = a
for i in arange(5):
    data_array = somefunction(data,newdata)  # I've tried hstack,vstack,dstack,array etc
    data_array[i] = newdata # this is what I would do in matlab but doesn't work in numpy
    data_list[len(data_list):] = [newdata] # this works
    newdata = newdata + 1000

Any help would be greatly appreciated.


- dharhas

More information about the SciPy-user mailing list