结合函数声明和表达式不起作用

时间:2019-11-23 18:28:32

标签: javascript function function-declaration function-expression

我正在分别检查函数声明和函数表达式,没问题

# various imports not printed here to conserve space

data_transform = transforms.Compose([
    transforms.ToTensor(),
    transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5))
])

the_dataset = torchvision.datasets.ImageFolder(root=rootdir,
                                       transform=data_transform)
dataset_loader = torch.utils.data.DataLoader(the_dataset,
                                         batch_size=64, shuffle=False,
                                         num_workers=4)

classes = ['original-images', 'tampered-images-0', 'tampered-images-1', 'tampered-images-2', 'tampered-images-3']

# I then show images in notebook thus

import numpy as np

def goshow(img):
    img = img / 2 + 0.5  # unnormalize
    plt.imshow(np.transpose(img, (1, 2, 0)), aspect='auto')  # convert from Tensor image

# Visualize a few images
dataiter = iter(dataset_loader)
images, labels = dataiter.next()
images = images.numpy() # convert images to numpy for display

# plot the images in the batch, along with the corresponding labels
fig = plt.figure(figsize=(25, 4))

# display some images
for idx in np.arange(10):
    ax = fig.add_subplot(2, 5, idx+1, xticks=[], yticks=[])
    goshow(images[idx])
    ax.set_title(classes[labels[idx]])

但是,如果我尝试将它们组合在一起,则函数声明将被忽略

function add(a,b){return a+b};
var add2 = function(a,b){return a+b};
add(1,2)// 3
add2(1,2) // 3

我没有真正的案例需要这种类型的声明,但是我试图理解为什么它不起作用

有人知道正确的文学作品吗?

0 个答案:

没有答案