[SciPy-user] help assigning arrays - global model output

Robert Kern robert.kern at gmail.com
Fri Jul 18 01:40:24 EDT 2008


On Fri, Jul 18, 2008 at 00:37, John [H2O] <washakie at gmail.com> wrote:
>
> Hello, I am trying to fill an array reading in unformatted binary data :-/
>
> I actually have most the code working now, and I have a F2Py module which
> reads the binary efficiently. My problem is assigning the arrays into the
> python multidimensional array.
>
> This works:
> G={}
> for date in dates:
>    data = F2Py.module.getdata()
>    # data is shape (180,360,3)
>    G[date] = data
>
> What I WANT is this:
>
> G=zeros((180,360,3,len(dates)))
> for i in range(len(dates)):
>    data = F2Py.module.getdata()
>    # data is shape (180,360,3)
>    G[:,:,:,i] = data
>
> But I get a shape mismatch error, something about not broadcasting an
> array....
>
> Could someone please provide comment on how I need to do this assignment?

Please double-check your shapes by printing out the actual shapes:


G=zeros((180,360,3,len(dates)))
for i in range(len(dates)):
   data = F2Py.module.getdata()
   print 'data: %s' % (data.shape,)
   print 'G[:,:,:,i]: %s' % (G[:,:,:,i].shape,)
   # data is shape (180,360,3)
   G[:,:,:,i] = data

-- 
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