形状不匹配:形状(2,)的值数组无法广播到形状(1,)的索引结果 [英] shape mismatch: value array of shape (2,) could not be broadcast to indexing result of shape (1,)

查看:1311
本文介绍了形状不匹配:形状(2,)的值数组无法广播到形状(1,)的索引结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了以下脚本,以使用 taylor图创建泰勒图 ://github.com/PeterRochford/SkillMetrics"rel =" nofollow noreferrer> SkillMetrics ,这是一个开放源代码Python库,用于根据观察结果计算模型预测.

I wrote the following script to create a taylor diagram using SkillMetrics, an open-source Python library for calculating model predictions against observations.

我写的脚本是:

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

产生:

sdev = array([ 0.02556107,  0.06264893,  0.06264893,  0.06264893])

crmsd = array([ 0.        ,  0.04918169,  0.04824091,  0.05082715])
ccoef = array([ 1.        ,  0.67423927,  0.68388202,  0.64162831])

然后我运行以下命令创建泰勒图:

I then ran the following to create the taylor diagram:

sm.taylor_diagram(sdev,crmsd,ccoef)

但是,我然后收到此错误:

However, I then received this error:

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

推荐答案

这是python 2问题.似乎skill_metrics package仅打算与python 3一起使用.该错误来自软件包的来源,您在这里没有做错任何事情.

This is a python 2 issue. Seems the skill_metrics package is intended to be used only with python 3. The error comes from the source of the package, you are not doing anything wrong here.

在python3中所讨论的行只发出警告,而不是错误.

In python3 the line in question should only throw a warning, not an error.

您唯一的机会可能是使用python 3或深入研究源代码.

The only chance you have is probably to either use python 3 or to dive into the source code.

  • 找到文件site-packages\skill_metrics\overlay_taylor_diagram_circles.py
  • 在此文件中找到行(应该在第50行附近)

  • Locate the file site-packages\skill_metrics\overlay_taylor_diagram_circles.py
  • inside this file, find the lines (should be around line 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)

  • 将其替换为

  • replace them with

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

  • 这篇关于形状不匹配:形状(2,)的值数组无法广播到形状(1,)的索引结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆