Python Forum
C'mon Indentation !!!
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
C'mon Indentation !!!
#1
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
Reply
#2
Post full traceback in error tags.
Reply
#3
It may be an editor issue. What is your python editor? Did you copy and paste from one source to another?
Reply
#4
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
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020