python return返回多个值后的处理

def load_datasets():

    train_file = r'D:\CNMU\AI\1第一个人工智能程序\datasets\train_catvnoncat.h5'
    test_file = r'D:\CNMU\AI\1第一个人工智能程序\datasets\test_catvnoncat.h5'

    train_datasets = h5py.File(train_file,'r')
    # train_datasets.keys()
    # <KeysViewHDF5 ['list_classes', 'train_set_x', 'train_set_y']>
    train_set_x = np.array(train_datasets['train_set_x'])
    train_set_y = np.array(train_datasets['train_set_y'])
    
    
    test_datasets = h5py.File(test_file,'r')
    test_set_x = np.array(test_datasets['test_set_x'])
    test_set_y = np.array(test_datasets['test_set_y'])
    
    classes = np.array(test_datasets['list_classes'])
    
    train_set_y = train_set_y.reshape(1,train_set_x.shape[0])
    test_set_y = test_set_y.reshape(1,test_set_x.shape[0])
    
    return train_set_x,train_set_y,test_set_x,test_set_y,classes

这里return返回了5个array,返回一个5元素的tuple;

train_set_x,train_set_y,test_set_x,test_set_y,classes = load_datasets()

用这段赋值后,就可以直接调用每一个array

已标记关键词 清除标记
相关推荐
©️2020 CSDN 皮肤主题: 数字20 设计师:CSDN官方博客 返回首页