Python Forum

Full Version: C'mon Indentation !!!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Obviously, I am new to python. I am getting indentation and space error, Doh Doh Doh Doh Doh

def plot_images(numImages, images, cls_true, cls_pred=None):
	
    assert len(images) == len(cls_true) == numImages
    
    # Create figure with 3x3 sub-plots.
    #fig, axes = plt.subplots(3, 3)
    remainder = numImages % 5
    
    if remainder == 0:
		row = numImages / 5
		
	else:
		row = remainder
    
    fig, axes = plt.subplots(row, 5)
    fig.subplots_adjust(hspace=0.3, wspace=0.3)

    for i, ax in enumerate(axes.flat):
        # Plot image.
        ax.imshow(images[i].reshape(img_shape), cmap='binary')

        # Show true and predicted classes.
        if cls_pred is None:
            xlabel = "True: {0}".format(cls_true[i])
        else:
            xlabel = "True: {0}, Pred: {1}".format(cls_true[i], cls_pred[i])

        ax.set_xlabel(xlabel)
        
        # Remove ticks from the plot.
        ax.set_xticks([])
        ax.set_yticks([])
        
    # Ensure the plot is shown correctly with multiple plots
    # in a single Notebook cell.
    plt.show()
Please help. thanks
Post full traceback in error tags.
It may be an editor issue. What is your python editor? Did you copy and paste from one source to another?
I guess OP mix tab and 4 spaces for indent and that is why I ask for the traceback. And to teach them to always post the full traceback