I have a large 4D data set and need to create a smaller 4D array from it. I am fairly new to python and am use to IDL or matlab. I read in my values then using the where function I find the index numbers I need for each dimension from smaller 1D arrays. I am trying to create a new array from these index numbers but I keep getting the shape mismatch error (can not be broacast to a single shape.
import numpy as n
import matplotlib.pyplot as plt
import Scientific.IO.NetCDF as S
file=S.NetCDFFile('wspd.mon.mean.nc',mode='r') #Opening File
Lat=file.variables['lat'].getValue() # Reading in the latitude variables, 73
Lon=file.variables['lon'].getValue() # Reading in the longitude variables, 144
Level=file.variables['level'].getValue() # Reading in the levels, 17 of them
Defaulttime=file.variables['time'].getValue() # Reading in the time, hrs since 1-1-1
Defaultwindspeed=file.variables['wspd'].getValue() # Reading in the windspeed(time, level, lat, lon)
Time=n.arange(len(Defaulttime))/12.+1948 #Creates time array into readable years with 12 months
goodtime=n.where((Time>=1948)&(Time<2013)) #Creates a time array for the years that I want, 1948-2012, since 2013 only has until October, I will not be using that data.
goodlat=n.where((Lat>=35)&(Lat<=50)) #Latitudes where the rockies and plains are in the US
plainslon=n.where((Lon>=275)&(Lon<=285))
Windspeedsplains=Defaultwindspeed[goodtime,:,goodlat,plainslon]
The error below is generated by the line above (last line of code).
>>>ValueError: shape mismatch: objects cannot be broadcast to a single shape
Defaultwindspeed
actually 4D? UseDefaultwindspeed.shape
orDefaultwindspeed.ndim
to check... – atomh33ls Nov 27 '13 at 11:40too many indices
. I think the problem is in the shapes ofgoodtime
,goodlat
, andplainslon
. @Cwilliams, what do you get if you printgoodtime.shape, goodlat.shape, plainslon.shape
? – askewchan Nov 27 '13 at 14:03