Skip to content

Instantly share code, notes, and snippets.

@yahyatawil
Last active September 1, 2021 08:35
Show Gist options
  • Save yahyatawil/3bef5b0078db5c677e785a1881c74f5c to your computer and use it in GitHub Desktop.
Save yahyatawil/3bef5b0078db5c677e785a1881c74f5c to your computer and use it in GitHub Desktop.

iteration with index and members:

for i, member in enumerate(array):

slicing (RGB example)

Img_array[x:x+w,y:y+h,:]

show more than one image in opencv2 imshow

temp_img1 = cv2.hconcat([cell1,neighbour_cells[0]])

temp_img2 = cv2.hconcat([temp_img1,neighbour_cells[1]])

temp_img3 = cv2.hconcat([temp_img2,neighbour_cells[2]])

temp_img4 = cv2.hconcat([temp_img3,neighbour_cells[3]])

cv2.imshow("cells",temp_img4)

build histogram

def build_histogram(lst):
    histo = {}
    for l in lst:
        histo[l] = histo.get(l, 0) + 1

Nested for

values = [val for gene in genes_int for val in gene] first for gene in genes_int then for val in gene

[att for gene in genes_int for i,att in enumerate(gene) if i== 1 ] [((att - v1_min) / (v1_max - v1_min)) for att in vec1 ] # min-max normalize

Stack of 2D Imgs

with open(filename) as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    line_count = 0
    for row in csv_reader:
        img = np.array([])
        if line_count == 0:
            line_count += 1
            continue
        else:
            labels = np.append(labels,row[0])
            img = np.array(row[1:785])
            img = img.astype(float)
            img = np.reshape(img, (28,28))
            images_l.append(img)
            line_count += 1
    images = np.stack(images_l,axis=0)  
            
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment