问题描述
我正在尝试运行一个 Python 脚本,该脚本将计算统计数学,并且在计算中的某处收到一个错误,该错误引发了以下关于不匹配形状(二维数组?)的错误。我的输入文件是一个 netCDF 文件,变量是模拟的天气雷达反射率。
错误信息:
Traceback (most recent call last):
File "calc_gen.py",line 75,in <module>
temp[ens_mean_index] = calc
ValueError: shape mismatch: value array of shape (635047,) Could not be broadcast to indexing result of shape (1905141,)
all_ref1km_lAmbert.nc: https://drive.google.com/file/d/1KhlnhB-0dhmt5JTS3E8YJ8QXm0bVyyfQ/view?usp=sharing
Python 脚本 (calc_gen.py):
import cartopy
import cartopy.crs as ccrs
import cartopy.feature as cfeature
import sys
import time
from array import array
import matplotlib.colors as mcolors
import matplotlib.pyplot as plt
#from mpl_toolkits.basemap import Basemap
import pygrib
import struct
from scipy.io import netcdf
import numpy as np
from netCDF4 import Dataset
from scipy.io.netcdf import netcdf_file
from numpy import arange,dtype
my_example_nc_file = 'all_ref1km_lAmbert.nc'
nc = Dataset(my_example_nc_file,mode='r')
lons = nc.variables['longitude'][:]
lats = nc.variables['latitude'][:]
all_member_data = nc.variables['REFD_1000maboveground'][:]
time = nc.variables['time'][:]
dx = 3.
nx = 1799
ny = 1059
count = 3
all_member_data = np.array(all_member_data)
ens_mean = np.mean(all_member_data,axis=0)
md_shape = ens_mean.shape
ens_dist = np.sort(all_member_data.flatten())[::-1]
calc = ens_dist[::count]
ens_mean_index = np.argsort(ens_mean.flatten())[::-1]
temp = np.empty_like(calc)
temp[ens_mean_index] = calc
calc = np.array(temp,dtype="<f")
calc_final = calc.reshape( md_shape )
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)