ValueError:x和y必须具有相同的第一尺寸,但形状为16,和20,

问题描述

我已经经历了堆栈溢出答案,但是没有找到合适的答案。我只是在两个Excel值之间绘制一个PSNR图。代码在下面提到

import os

import numpy as np
from scipy.misc import imread
import matplotlib.pyplot as plt

line = True

lstm_ssim = np.genfromtxt('test/psnr/bpg_psnr.csv',delimiter=',')
lstm_ssim = lstm_ssim[:,:-1]
if line:
    lstm_ssim = np.mean(lstm_ssim,axis=0)
    lstm_bpp = np.arange(1,17) / 192 * 24
    plt.plot(lstm_bpp,lstm_ssim,label='LSTM',marker='o')
else:
    lstm_bpp = np.stack([np.arange(1,17) for _ in range(24)]) / 192 * 24
    plt.scatter(
        lstm_bpp.reshape(-1),lstm_ssim.reshape(-1),marker='o')

jpeg_ssim = np.genfromtxt('test/psnr/jpeg_psnr.csv',')
jpeg_ssim = jpeg_ssim[:,:-1]
if line:
    jpeg_ssim = np.mean(jpeg_ssim,axis=0)

jpeg_bpp = np.array([
    os.path.getsize('test/jpeg/kodim{:02d}/{:02d}.jpg'.format(i,q)) * 8 /
    (imread('test/jpeg/kodim{:02d}/{:02d}.jpg'.format(i,q)).size // 3)
    for i in range(1,25) for q in range(1,21)
]).reshape(24,20)

if line:
    jpeg_bpp = np.mean(jpeg_bpp,axis=0)
    plt.plot(jpeg_bpp,jpeg_ssim,label='JPEG',marker='x')
else:
    plt.scatter(
        jpeg_bpp.reshape(-1),jpeg_ssim.reshape(-1),marker='x')

plt.xlim(0.,2.)
plt.ylim(0.7,1.0)
plt.xlabel('bit per pixel')
plt.ylabel('PSNR')
plt.legend()
plt.show()

excel中有20列和24行。

enter image description here

Python文件错误

Traceback (most recent call last):
  File "test/psnr/draw_psnr.py",line 14,in <module>
    plt.plot(lstm_bpp,marker='o')
  File "/home/khawar/anaconda3/envs/RNN_Fresh/lib/python3.5/site-packages/matplotlib/pyplot.py",line 2749,in plot
    *args,scalex=scalex,scaley=scaley,data=data,**kwargs)
  File "/home/khawar/anaconda3/envs/RNN_Fresh/lib/python3.5/site-packages/matplotlib/__init__.py",line 1785,in inner
    return func(ax,*args,**kwargs)
  File "/home/khawar/anaconda3/envs/RNN_Fresh/lib/python3.5/site-packages/matplotlib/axes/_axes.py",line 1604,in plot
    for line in self._get_lines(*args,**kwargs):
  File "/home/khawar/anaconda3/envs/RNN_Fresh/lib/python3.5/site-packages/matplotlib/axes/_base.py",line 393,in _grab_next_args
    yield from self._plot_args(this,kwargs)
  File "/home/khawar/anaconda3/envs/RNN_Fresh/lib/python3.5/site-packages/matplotlib/axes/_base.py",line 370,in _plot_args
    x,y = self._xy_from_xy(x,y)
  File "/home/khawar/anaconda3/envs/RNN_Fresh/lib/python3.5/site-packages/matplotlib/axes/_base.py",line 231,in _xy_from_xy
    "have shapes {} and {}".format(x.shape,y.shape))
ValueError: x and y must have same first dimension,but have shapes (16,) and (20,)
(RNN_Fresh) khawar@khawar-B365-HD3:~/Desktop/RNN_Fresh/pytorch-image-comp-rnn$ 

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)