[SciPy-User] numpy.squeeze not squeezing

Robert Kern robert.kern at gmail.com
Wed Sep 30 18:05:58 EDT 2009


On Wed, Sep 30, 2009 at 17:03, Bruce Ford <bruce at clearscienceinc.com> wrote:
> Robert, thanks for responding.  Your response makes me things
> something in my array is preventing squeeze form working correctly.
> Here's a cleaned up version of my script:
>
>
> #!/usr/local/env python
> from mpl_toolkits.basemap import Basemap
> import numpy as np #used to preform simple math functions on data
> from netCDF4 import Dataset
> #decide which file to open
> year = 1995
> month = "%02d" % 5
>
> #Set up file names
> filename = "/data/ww3/NetCDF/3_hourly/ww3."+str(year)+str(month)+ ".nc"
> opennc = Dataset(filename, mode="r")
>
> swh = opennc.variables['sig_wav_ht']
> print swh.shape  #gives (248,1,181,360)
> swh1 = np.squeeze(swh)
>
> print 'SWH shape: ', swh1.shape  #gives ()

print type(swh1)

I'm not sure that swh1 is actually an ndarray. It might be a different
class that masquerades as a numpy array.

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