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

Robert Kern robert.kern at gmail.com
Wed May 21 13:45:20 EDT 2008


On Wed, May 21, 2008 at 12:05 PM, Dharhas Pothina
<Dharhas.Pothina at twdb.state.tx.us> wrote:
> Hi,
>
> 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.

Keep appending to the list to build it up. Then make an array from
that list using array().

from numpy import array

a = array([[[  1,   2],[  3,   4],[  5,   6]],[[101, 102],[103,
104],[105, 106]],[[201, 202],[203, 204],[205, 206]]])
data_list=[]
newdata = a
for i in arange(5):
   data_list.append(newdata)  # This is the idiomatic way to append to a list.
   newdata = newdata + 1000

data_array = array(data_list)

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco



More information about the SciPy-User mailing list