Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 在混乱矩阵中获取列表索引超出范围错误_Python 2.7_Pygame_Confusion Matrix - Fatal编程技术网

Python 2.7 在混乱矩阵中获取列表索引超出范围错误

Python 2.7 在混乱矩阵中获取列表索引超出范围错误,python-2.7,pygame,confusion-matrix,Python 2.7,Pygame,Confusion Matrix,此文件出现如下错误: import pygame import numpy import pickle import pdb import sys def printConfMatrix(grid,num): # Define some colors BLACK = ( 0, 0, 0) WHITE = ( 255, 255, 255) GREEN = ( 0, 255, 0) RED = ( 255,

此文件出现如下错误:

import pygame
import numpy
import pickle
import pdb
import sys


def printConfMatrix(grid,num):
    # Define some colors
    BLACK    = (   0,   0,   0)
    WHITE    = ( 255, 255, 255)
    GREEN    = (   0, 255,   0)
    RED      = ( 255,   0,   0)

    # This sets the width and height of each grid location
    width  = 20
    height = 20

    # This sets the margin between each cell
    margin = 5

    # Initialize pygame
    pygame.init()

    # Set the height and width of the screen
    size = [255, 255]
    screen = pygame.display.set_mode(size)

    # Set title of screen
    pygame.display.set_caption("Array Backed Grid")

    # Set the screen background
    screen.fill(WHITE)

    # Draw the grid
    for row in range(10):
        for column in range(10):
            color = (WHITE[0]-grid[row,column]*10,WHITE[1]-grid[row,column]*10,WHITE[2]-grid[row,column]*10)
            pygame.draw.rect(screen,
                             color,
                             [(margin+width)*column+margin,
                              (margin+height)*row+margin,
                              width,
                              height])


    # Go ahead and update the screen with what we've drawn.
    pygame.display.flip()
    pygame.image.save(screen, "confusionMatrix" + num + ".jpg")
    #pdb.set_trace()
    # Be IDLE friendly. If you forget this line, the program will 'hang'
    # on exit.
    #pygame.quit()


f = open("confusion" + sys.argv[1] + ".pickle",'r')
grid = pickle.load(f)

printConfMatrix(grid,sys.argv[1])
c:\Python27\Scripts>python D:\pr\final\u project\code\conflusion.py
回溯(最近一次呼叫最后一次):
文件“D:\pr\final\u project\code\conflusion.py”,第68行,在
f=打开(“混乱”+sys.argv[1]+“.pickle”,'r')
索引器:列表索引超出范围

索引器表示您试图访问列表中不存在的索引。在您的例子中,列表是---一个命令行参数列表

要消除该错误,请使用单个参数调用脚本,该参数是pickle混淆矩阵的文件名后缀。例如,如果矩阵位于名为
混乱\u final.pickle
的文件中,则应运行

c:\Python27\Scripts>python D:\pr\final_project\code\confusion.py
Traceback (most recent call last):
  File "D:\pr\final_project\code\confusion.py", line 68, in <module>
    f = open("confusion" + sys.argv[1] + ".pickle",'r')
IndexError: list index out of range
python D:\pr\final_project\code\confusion.py final_