Deep Learning is a subfield of Machine Learning which learns from example. It is highly used in driverless cars, sentiment analysis, credit scoring, fraud detection etc. Below is the list of free Deep Learning ebooks with their download link curated from different sources. Hope, you will find them useful in preparing for Deep Learning.
If you would like to list your ebook free of cost or would like to contribute, do comment or reach out to us. Did you check about other free eBooks about:
Tensorflow eBooks : Click Here
Machine Learning eBooks: Click Here
Question:
Write a program to perform shell sort on [85,63,0,12,47,96,52]
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
def shellSort (numbers,array_size): increment = array_size / 2; while (increment > 0): for i in range (0,array_size): j = i; temp = numbers[i]; while ((j >= increment) and (numbers[j-increment] > temp)): numbers[j] = numbers[j - increment]; j = j - increment; numbers[j] = temp; if (increment == 2): increment = 1; else : increment = increment * 5 / 11; numbers=[85,63,0,12,47,96,52] array_size=len(numbers) shellSort ( numbers,array_size) print numbers |
Explanation:
Step 1 − Initialize the value of h
Step 2 − Divide the list into smaller sub-list of equal interval h
Step 3 − Sort these sub-lists using insertion sort
Step 4 − Repeat until complete list is sorted
Output:
1 |
[0, 12, 47, 52, 63, 85, 96] |
Question:
Write a program to perform merge sort on [85,63,0,12,47,96,52]
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
def mergeSort(alist): print("Splitting ",alist) if len(alist)>1: mid = len(alist)//2 lefthalf = alist[:mid] righthalf = alist[mid:] mergeSort(lefthalf) mergeSort(righthalf) i=0 j=0 k=0 while i < len(lefthalf) and j < len(righthalf): if lefthalf[i] < righthalf[j]: alist[k]=lefthalf[i] i=i+1 else: alist[k]=righthalf[j] j=j+1 k=k+1 while i < len(lefthalf): alist[k]=lefthalf[i] i=i+1 k=k+1 while j < len(righthalf): alist[k]=righthalf[j] j=j+1 k=k+1 print("Merging ",alist) alist = [85,63,0,12,47,96,52] mergeSort(alist) print(alist) |
Explanation:
Step 1 − if it is only one element in the list it is already sorted, return.
Step 2 − divide the list recursively into two halves until it can no more be divided.
Step 3 − merge the smaller lists into new list in sorted order.
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
Splitting [85, 63, 0, 12, 47, 96, 52] Splitting [85, 63, 0] Splitting [85] Merging [85] Splitting [63, 0] Splitting [63] Merging [63] Splitting [0] Merging [0] Merging [0, 63] Merging [0, 63, 85] Splitting [12, 47, 96, 52] Splitting [12, 47] Splitting [12] Merging [12] Splitting [47] Merging [47] Merging [12, 47] Splitting [96, 52] Splitting [96] Merging [96] Splitting [52] Merging [52] Merging [52, 96] Merging [12, 47, 52, 96] Merging [0, 12, 47, 52, 63, 85, 96] [0, 12, 47, 52, 63, 85, 96] |
Question:
Write a program to sort ‘GlobalSQA’ lexiographically
Program:
1 2 3 4 |
def lexicographi_sort(s): return sorted(sorted(s), key=str.upper) print(lexicographi_sort('GlobalSQA')) |
Explanation:
The lexicographic or lexicographical order (also known as lexical order, dictionary order, alphabetical order or lexicographical product) is a generalization of the way the alphabetical order of words is based on the alphabetical order of their component letters. The sorted function sorts it for you.
Output:
1 |
['A', 'a', 'b', 'G', 'l', 'l', 'o', 'Q', 'S'] |
Question:
Write a program to perform bubble sort on [85,63,0,12,47,96,52]
Program:
1 2 3 4 5 6 7 8 9 10 11 |
def bubbleSort(alist): for passnum in range(len(alist)-1,0,-1): for i in range(passnum): if alist[i]>alist[i+1]: temp = alist[i] alist[i] = alist[i+1] alist[i+1] = temp alist = [85,63,0,12,47,96,52] bubbleSort(alist) print(alist) |
Explanation:
Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order.
Output:
1 |
[0, 12, 47, 52, 63, 85, 96] |
Question:
Write a program to perform insertion sort on [85, 63, 0, 12, 47, 96, 52]
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
def insertionSort(alist): for index in range(1,len(alist)): currentvalue = alist[index] position = index while position>0 and alist[position-1]>currentvalue: alist[position]=alist[position-1] position = position-1 alist[position]=currentvalue alist = [85, 63, 0, 12, 47, 96, 52] insertionSort(alist) print(alist) |
Explanation:
Step 1 − If it is the first element, it is already sorted. return 1
Step 2 − Pick next element
Step 3 − Compare with all elements in the sorted sub-list
Step 4 − Shift all the elements in the sorted sub-list that is greater than the value to be sorted
Step 5 − Insert the value
Step 6 − Repeat until list is sorted
Output:
1 |
[0, 12, 47, 52, 63, 85, 96] |
Question:
Write a program to perform Quick sort on [85, 63, 0, 12, 47, 96, 52]
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
def quickSort(alist): quickSortHelper(alist,0,len(alist)-1) def quickSortHelper(alist,first,last): if first<last: splitpoint = partition(alist,first,last) quickSortHelper(alist,first,splitpoint-1) quickSortHelper(alist,splitpoint+1,last) def partition(alist,first,last): pivotvalue = alist[first] leftmark = first+1 rightmark = last done = False while not done: while leftmark <= rightmark and alist[leftmark] <= pivotvalue: leftmark = leftmark + 1 while alist[rightmark] >= pivotvalue and rightmark >= leftmark: rightmark = rightmark -1 if rightmark < leftmark: done = True else: temp = alist[leftmark] alist[leftmark] = alist[rightmark] alist[rightmark] = temp temp = alist[first] alist[first] = alist[rightmark] alist[rightmark] = temp return rightmark alist =[85, 63, 0, 12, 47, 96, 52] quickSort(alist) print(alist) |
Explanation:
Quicksort is a divide and conquer algorithm. Quicksort first divides a large array into two smaller sub-arrays: the low elements and the high elements. Quicksort can then recursively sort the sub-arrays.
The steps are:
The base case of the recursion is arrays of size zero or one, which never need to be sorted.
Output:
1 |
[0, 12, 47, 52, 63, 85, 96] |
Question:
Write a program to find the sum of diagonal elements in a matrix.
Program:
1 2 3 4 |
a = [[11,2,4],[4,5,6],[10,8,-12]] n=len(a) sum_second_diagonal=sum([a[i][j] for i in range(n) for j in range(n) if i+j==n-1]) print (sum_second_diagonal) |
Explanation:
Comprehensions provide a concise way to create new set of elements that satisfy a given condition from an iterable. Here the iterable is the for loop looking for diagonal elements. The list thus formed is passed to sum which returns the sum of elements in the list.
Output:
1 |
19 |
Question:
Write a program to reverse a number
Program:
1 2 3 4 5 6 7 8 9 10 11 |
num = (input("Enter any number: ")) reverse = 0 try: val = int(num) while val > 0: reminder = val % 10 reverse = (reverse * 10) + reminder val //= 10 print('Reverse of given number is : ', reverse) except ValueError: print("That's not a valid number, Try Again !") |
Explanation:
The while loop contains the statements to isolate or separate the digits of a number ,which is then multiplied to 10 and sums the reminder. Thus you get the reverse.
Let’s try it out
Say n=366
while val>0//True, then reminder is 6,reverse also 6 and val is 36
while 36>0//True, then reminder is 6, reverse is (6*10)+6 =66, and val is 3
while 3>0// True, then reminder is 3,reverse is (66*10)+3=663 and val is 0
Hence reverse is 663
Output:
1 2 |
Enter any number: 895 Reverse of given number is : 598 |
Question:
Write a program to find the sum of diagonal elements
Program:
1 2 3 4 5 6 7 8 |
a = [[11,2,4],[4,5,6],[10,8,-12]] n=len(a) sumn=0 for i in range(n): for j in range(n): if i+j==n-1: sum+=a[i][j] print (sumn) |
Explanation:
Diagonal elements are those where i=j, as in a[0][0], a[1][1] etc.the for loop cheks every instant if i is equal to j, if true value of a[i][j] is incremented to sum.
Output:
1 |
19 |
Question:
Write a program to find the length of a string without inbuilt function
Program:
1 2 3 4 5 6 |
def strlen(s): if s == "": return 0 return s.rindex(s[-1]) + 1 s= "GlobalSQA" print(strlen(s)) |
Explanation:
The strlen function return 0 if the string is empty. Otherwise it adds one to the index position of it;s last element obtained by s.rindex.
Output:
1 |
9 |
Question:
Write a program to transpose two matrices
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#! usr/bin/python m=int(input("ENTER MARTIX ROW SIZE m : ")) n=int(input("ENTER MARTIX COLUMN SIZE n : ")) #initializing matrix elements as 0 X = [[0]*n for j in range(m)] Y = [[0]*m for j in range(n)] #getting input to matrix X for i in range (m): for j in range (n): print ('entry in row: ',i+1,' column: ',j+1) X[i][j] = int(input()) #printing first matrix X print "ORIGINAL MATRIX : " for i in range (m): for j in range (n): print X[i][j],"\t", print "\n" #transpose of matrix X for i in range (m): for j in range (n): Y[j][i]=X[i][j] #printing transpose matrix Y print "TRANSPOSE MATRIX : " for i in range (n): for j in range (m): print Y[i][j],"\t", print "\n" |
Explanation:
The transpose of a matrix is an operator which flips a matrix over its diagonal, that is it switches the row and column indices of the matrix by producing another matrix denoted as AT (also written A′, Atr, tA or At). It is achieved by any one of the following equivalent actions:
Formally, the i th row, j th column element of AT is the j th row, i th column element of A:
If A is an m × n matrix then AT is an n × m matrix.
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
ENTER MARTIX ROW SIZE m : 2 ENTER MARTIX COLUMN SIZE n : 2 entry in row: 1 column: 1 8 entry in row: 1 column: 2 9 entry in row: 2 column: 1 4 entry in row: 2 column: 2 8 ORIGINAL MATRIX : 8 4 9 8 TRANSPOSE MATRIX : 8 9 4 8 |
Question:
Fetch all links from google home page
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import urllib2 import re req=urllib2.Request('https://www.google.com') #connect to a URL website = urllib2.urlopen(req) #read html code html = website.read() #use re.findall to get all the links links = re.findall('"((http|ftp)s?://.*?)"', html) for i in links: print i |
Explanation:
The urllib2
module defines functions and classes which help in opening URLs (mostly HTTP) in a complex world — basic and digest authentication, redirections, cookies and more.
re module provides regular expression matching operations similar to those found in Perl. Both patterns and strings to be searched can be Unicode strings as well as 8-bit strings.
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
('http://schema.org/WebPage', 'http') ('https://www.google.co.in/imghp?hl=en&tab=wi', 'http') ('https://maps.google.co.in/maps?hl=en&tab=wl', 'http') ('https://play.google.com/?hl=en&tab=w8', 'http') ('https://www.youtube.com/?gl=IN&tab=w1', 'http') ('https://news.google.co.in/nwshp?hl=en&tab=wn', 'http') ('https://mail.google.com/mail/?tab=wm', 'http') ('https://drive.google.com/?tab=wo', 'http') ('https://www.google.co.in/intl/en/options/', 'http') ('http://www.google.co.in/history/optout?hl=en', 'http') ('https://accounts.google.com/ServiceLogin?hl=en&passive=true&continue=https://www.google.co.in/%3Fgfe_rd%3Dcr%26ei%3D83RYWbugK9WkvwT7j4SwCA', 'http') ('http://www.google.co.in/services/', 'http') ('https://plus.google.com/104205742743787718296', 'http') ('https://www.google.co.in/setprefdomain?prefdom=US&sig=__xO-fFja9LlrL0EjCUtIDcyG3flI%3D', 'http') |