形状不匹配:形状(2,)的值数组无法广播到形状(1,)的索引结果

2024-05-18 06:12:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我编写了下面的脚本来使用SkillMetrics创建一个taylor diagram,这是一个开源的Python库,用于根据观察结果计算模型预测。在

我写的剧本是:

import skill_metrics as sm 

# Arrange datasets in array
stats1 = np.array([ref,m1])
stats2 = np.array([ref,m2])
stats3 = np.array([ref,m3])

# calculating statistics
taylor_stats1 = sm.taylor_statistics(stats1[0],stats1[1])
taylor_stats2 = sm.taylor_statistics(stats2[0],stats2[1])
taylor_stats3 = sm.taylor_statistics(stats3[0],stats3[1])

# Store statistics in arrays
sdev = np.array([taylor_stats1['sdev'][0], taylor_stats1['sdev'][1],
                 taylor_stats2['sdev'][1], taylor_stats3['sdev'][1]])
crmsd = np.array([taylor_stats1['crmsd'][0], taylor_stats1['crmsd'][1],
                  taylor_stats2['crmsd'][1], taylor_stats3['crmsd'][1]])
ccoef = np.array([taylor_stats1['ccoef'][0], taylor_stats1['ccoef'][1],
                  taylor_stats2['ccoef'][1], taylor_stats3['ccoef'][1]])

产生:

^{pr2}$

然后,我运行以下步骤来创建泰勒图:

sm.taylor_diagram(sdev,crmsd,ccoef)

但是,我收到了这个错误:

shape mismatch: value array of shape (2,) could not be broadcast to indexing result of shape (1,)

Tags: inrefnparraydiagramsmstatisticsshape
1条回答
网友
1楼 · 发布于 2024-05-18 06:12:30

这是Python2的问题。似乎skill_metrics package只打算与python3一起使用。错误来自程序包的源代码,您没有做错任何事情。在

在python3中,the line in question应该只抛出一个警告,而不是一个错误。在

您唯一的机会可能是使用Python3或深入研究源代码。在

  • 找到文件site-packages\skill_metrics\overlay_taylor_diagram_circles.py
  • 在这个文件中,找到行(应该在第50行左右)

    # now really force points on x/y axes to lie on them exactly
    inds = range(0,len(th),(len(th)-1) // 4)
    xunit[inds[1:3:2]] = np.zeros(2)
    yunit[inds[0:4:2]] = np.zeros(3)
    
  • 替换为

    inds = range(0,len(th),(len(th)-1) // 4)
    xunit[74] = 0
    yunit[148] = 0
    

相关问题 更多 >