简体   繁体   中英

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

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

The script I wrote was:

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

which produces:

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

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.

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

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

  • 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 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM