dimanche 4 septembre 2016

if 'statement' : 'statement' if 'statement' else 'statement' How this double if and else work?

I cant understand this double if and else statement

full code is below and where is cant understand is


if not imgs[i].startswith('.'):
                label[j]=0 if imgs[i].split('.')[0]=='cat' else 1


def LoadDirImgList(sampleNum,path): 
    data = np.empty((sampleNum,3,32,32),dtype="float32")
    label = np.empty((sampleNum,),dtype ="uint8")
    imgs = os.listdir(path)
    num = len(imgs)
    j=0
    for i in range(num):
        if not imgs[i].startswith('.'):
            label[j]=0 if imgs[i].split('.')[0]=='cat' else 1
            img = Image.open(path+imgs[i])
            arr = np.asarray (img, dtype ="float32")
            data [j,:,:,:] = [arr[:,:,0],arr[:,:, 1],arr[:,:, 2]] 
            j=j+1
    return data, label

Aucun commentaire:

Enregistrer un commentaire