2016-07-18 2 views
0

Eddy Kinetic Energy를 플롯하기위한 Python 코드를 작성 중입니다. 나는 Python에 상당히 익숙하지 않으며 내가 얻은 오류에 대해 혼란 스럽다. 지도에 내 데이터를 플로팅하는 것에 대해 걱정하지 않아도 단지 음모를 낼 수 있는지 알고 싶습니다.왜이 오류가 발생합니까? TypeError : 입력은 2D 배열이어야합니다.

import numpy as np 
import matplotlib.pyplot as plt 
import matplotlib.cm as cm 
from pylab import * 
from netCDF4 import Dataset 
from mpl_toolkits.basemap import Basemap 
import matplotlib.cm as cm 

from mpl_toolkits.basemap import shiftgrid 
test = Dataset('p.34331101.atmos_daily.nc', 'r') 

lat = test.variables['lat'][:] 
lon = test.variables['lon'][:] 
level = test.variables['level'][5] 
time = test.variables['time'][:] 
u = test.variables['ucomp'][:] 
v = test.variables['vcomp'][:] 
temp = test.variables['temp'][:] 

print(lat.shape) 
print(u.shape) 
#uz = np.reshape(u, (30, 26, 90)) 
uzm = np.nanmean(u, axis=3) 

#vz = np.reshape(v, (30, 26, 90)) 
vzm = np.nanmean(v, axis=3) 
print(uzm.shape) 

ustar = u-uzm[:,:,:,np.newaxis] 
vstar = v-vzm[:,:,:,np.newaxis] 

EKE = np.nanmean(.5*(ustar**2 + vstar**2), axis=3) 

EKE1 = np.asarray(EKE) 
%matplotlib inline 

print(EKE.shape) 

levels=[-10, -5, 0, 5, 10] 
plt.contour(EKE[1,1,:]) 
#EKE is time, level, lat and the shape is (30, 26, 90) 

형식 오류 : 입력이 2 차원 배열해야합니다 여기에 내 코드 및 오류입니다.

답변

0

브렛 (Bret), 오류와 관련하여 좀 더 자세한 정보를 포함하면 도움이 될 것입니다. 라인 번호를 보지 않았습니까?

문제가 1D 배열을 contour()로 전달하고있는 것 같아요. 이는 대개 직관적 인 것처럼 보이지만 numpy는 색인에서 단일 값을 지정할 때 '자동으로'크기를 줄입니다.

즉하려고

print(EKE.shape) 
print(EKE[1,1,:].shape) 
print(EKE[1:2,1:2,:].shape)