Below is the list of free ebooks on Elasticsearch, Kibana, ELK Stack, Lucene, Logstash with their download link curated from different sources. Hope, you will find them useful in preparing for Deep Learning. There are in different formats like mobi, epub and pdf. In case, you don’t have mobi or epub reader please download it separately to view those files. I expect you must be having pdf viewer.
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
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 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 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:
Write a python program to generate passwords
Program:
1 2 3 4 5 |
import string from random import * characters = string.ascii_letters + string.punctuation + string.digits password = "".join(choice(characters) for x in range(randint(8, 16))) print (password) |
Explanation:
Following are the criteria for creating a password:
1. At least 1 letter between [a-z]
2. At least 1 number between [0-9]
1. At least 1 letter between [A-Z]
3. At least 1 character from [$#@]
4. Minimum length of transaction password: 6
5. Maximum length of transaction password: 12
Output:
1 |
-|>GR5UZY3 |
Question:
Calculate area of a rectangle using classes
Program:
1 2 3 4 5 6 7 8 9 10 11 12 |
class rect(): def __init__(self,breadth,length): self.breadth=breadth self.length=length def area(self): return self.breadth*self.length a=int(input("Enter length of rectangle: ")) b=int(input("Enter breadth of rectangle: ")) obj=rect(a,b) # Creating an object 'obj' of class rect print "Area of rectangle:",obj.area() |
Explanation:
A class rect is created with two breadth and length, and method area which tabulates the area of the rectangle.
An object obj of class rect is created and used
Output:
1 2 3 |
Enter length of rectangle: 10 Enter breadth of rectangle: 20 Area of rectangle: 200 |
Question:
Create a list of even numbers between 0 and 10 using list comprehension.
Program:
1 2 |
listl=[i for i in range (10) if(i%2==0)] print listl |
Explanation:
List comprehensions provide a concise way to create lists.
It consists of brackets containing an expression followed by a for clause, then
zero or more for or if clauses. The expressions can be anything, meaning you can
put in all kinds of objects in lists.
List comprehensions provide a concise way to create new list of elements that satisfy a given condition from an iterable. Here the iterable prints out even numbers.
Output:
1 |
[0, 2, 4, 6, 8] |
Question :
Write a program to print prime numbers within a range
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 |
#Accept the range from user lower = int(input("Enter lower range: ")) upper = int(input("Enter upper range: ")) print "Prime numbers between",lower,"and",upper,"are:", for num in range(lower,upper + 1): # prime numbers are greater than 1 if num > 1: for i in range(2,num): if (num % i) == 0: break else: print num, |
Explanation:
A prime number is a number that is divisible only by itself and 1 (e.g. 2, 3, 5, 7, 11).
Output:
1 2 3 4 5 |
Enter lower range: 2 Enter upper range: 10 Prime numbers between 2 and 10 are: 2 3 5 7 |
Question:
Write a program to show the difference between range() and xrange() function
Program:
1 2 3 4 5 6 7 |
import sys r=range(10000) x=xrange(10000) print (sys.getsizeof(r)) #output:40036 print (sys.getsizeof(x)) #output:20 #sys.getsizeof() returns the memory size occupied by a variable or object |
Explanation:
The variable holding the range created using range() uses so much memory compared to
the variable created using xrange()
The reason is that range creates a list holding all the values
while xrange creates an object that can iterate over the numbers on demand.
Eventhough the xrange is memory efficient, the price we have to pay
for this efficieny is access time. The range variable created with range()
will have a faster access time compare to the variable created with xrange()
as it is entirely stored in the memory so it is readily available
whereas the variable created with xrange() have to load its contents
to memory ‘on demand’ only. So time efficiency is a drawback of xrange()
Output:
1 2 |
80072 40 |
Question:
Perform the following operations on the below tuple (‘abc’, ‘def’, ‘ghi’, ‘jklm’, ‘nopqr’, ‘st’, ‘uv’, ‘wxyz’, ’23’, ‘s98’, ‘123’, ’87’)
prints the length of the tuple
Slicing
Reverse all items in the tuple
Removing whole tuple
Concatenate two tuples
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 |
tup = ('abc', 'def', 'ghi', 'jklm', 'nopqr', 'st', 'uv', 'wxyz', '23', 's98', '123', '87') # prints the length of the tuple print('\ntuple: ', tup) print('Length of the tuple is : ', len(tup)) # Slicing # shows only items starting from 0 upto 3 print('\ntuple: ', tup) print('tuple showing only items starting from 0 upto 3\n', tup[:3]) # shows only items starting from 4 to the end print('\ntuple: ', tup) print('tuple showing only items starting from 4 to the end\n', tup[4:]) # shows only items starting from 2 upto 6 print('\ntuple: ', tup) print('tuple showing only items starting from 2 upto 6\n', tup[2:6]) # reverse all items in the tuple print('\ntuple: ', tup) print('tuple items reversed \n', tup[::-1]) # removing whole tuple del tup tup_0 = ("ere", "sad") tup_1 = ("sd", "ds") print('\nfirst tuple: ', tup_0) print('second tuple: ', tup_1) tup = tup_0 + tup_1 print('Concatenation of 2 tuples \n', tup) |
Explanation:
A tuple is a sequence of immutable Python objects. Tuples are sequences, just like lists. The differences between tuples and lists are, the tuples cannot be changed unlike lists and tuples use parentheses, whereas lists use square brackets.
Output:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
tuple: ('abc', 'def', 'ghi', 'jklm', 'nopqr', 'st', 'uv', 'wxyz', '23', 's98', '123', '87') Length of the tuple is : 12 tuple: ('abc', 'def', 'ghi', 'jklm', 'nopqr', 'st', 'uv', 'wxyz', '23', 's98', '123', '87') tuple showing only items starting from 0 upto 3 ('abc', 'def', 'ghi') tuple: ('abc', 'def', 'ghi', 'jklm', 'nopqr', 'st', 'uv', 'wxyz', '23', 's98', '123', '87') tuple showing only items starting from 4 to the end ('nopqr', 'st', 'uv', 'wxyz', '23', 's98', '123', '87') tuple: ('abc', 'def', 'ghi', 'jklm', 'nopqr', 'st', 'uv', 'wxyz', '23', 's98', '123', '87') tuple showing only items starting from 2 upto 6 ('ghi', 'jklm', 'nopqr', 'st') tuple: ('abc', 'def', 'ghi', 'jklm', 'nopqr', 'st', 'uv', 'wxyz', '23', 's98', '123', '87') tuple items reversed ('87', '123', 's98', '23', 'wxyz', 'uv', 'st', 'nopqr', 'jklm', 'ghi', 'def', 'abc') first tuple: ('ere', 'sad') second tuple: ('sd', 'ds') Concatenation of 2 tuples ('ere', 'sad', 'sd', 'ds') |
Question:
Write a program to check the validity of password input by users.
Accept a sequence of comma separated passwords and check them according to the above criteria. Print the valid passwords
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import re value = [] items=[x for x in raw_input("Enter passwords separated by commas for checking validity.Press Enter to end.\n").split(',')] for p in items: if len(p)<6 or len(p)>12: continue else: pass if not re.search("[a-z]",p): continue elif not re.search("[0-9]",p): continue elif not re.search("[A-Z]",p): continue elif not re.search("[$#@]",p): continue elif re.search("\s",p): continue else: pass value.append(p) print "Valid passwords",value |
Explanation:
Following are the criteria for checking the password:
1. At least 1 letter between [a-z]
2. At least 1 number between [0-9]
3. At least 1 letter between [A-Z]
4. At least 1 character from [$#@]
5. Minimum length of transaction password: 6
6. Maximum length of transaction password: 12
Output:
1 2 3 4 5 |
Enter passwords separated by commas for checking validity.Press Enter to end globalsqa,#GlobalSQA2 Valid passwords ['#GlobalSQA2'] |
Question:
Write a program to print the following pattern
1 2 3 4 5 |
* * * * * * * * * * * * * * * |
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 |
# on to demonstrate printing pattern def invert_triangle(n): # number of spaces k = 2*n - 2 # outer loop to handle number of rows for i in range(0, n): # inner loop to handle number spaces # values changing acc. to requirement for j in range(0, k): print(end=" ") # decrementing k after each loop k = k - 2 # inner loop to handle number of columns # values changing acc. to outer loop for j in range(0, i+1): # printing stars print("* ", end="") # ending line after each row print("\r") n = 5 invert_triangle(n) |
Question:
Print the below pattern
1 2 3 4 5 6 7 8 |
1 2 1 3 2 1 4 3 2 1 5 4 3 2 1 6 5 4 3 2 1 7 6 5 4 3 2 1 8 7 6 5 4 3 2 1 |
Program:
1 2 3 4 |
for i in range(1, 8 + 1): for j in range(i, 0, -1): print(j), print("") |
Question:
Write a program to print the following pattern
1 2 3 4 5 |
* * * * * * * * * * * * * * * |
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 |
def pyramid(n): # number of spaces k = 2*n - 2 # outer loop to handle number of rows for i in range(0, n): # inner loop to handle number spaces # values changing acc. to requirement for j in range(0, k): print(end=" ") # decrementing k after each loop k = k - 1 # inner loop to handle number of columns # values changing acc. to outer loop for j in range(0, i+1): # printing stars print("* ", end="") # ending line after each row print("\r") n = 5 pyramid(n) |
Question:
With a given list [5,3,5,3,6,8,3,1,9,4,5,9,0,7], write a program to print this list after removing all duplicate values with original order reserved.
Program:
1 2 3 4 5 6 7 8 9 10 11 12 |
<strong>def removeD</strong>uplicate( li ): newli=[] seen = set() for item in li: if item not in seen: seen.add( item ) newli.append(item) return newli li=[5,3,5,3,6,8,3,1,9,4,5,9,0,7] print (removeDuplicate(li)) |
Explanation:
Set() function stores number of values without duplicate.
Output:
1 |
[5, 3, 6, 8, 1, 9, 4, 0, 7] |
Question :
Swap two variables without using a third temporary variable
Program:
1 2 3 4 5 |
num1= int(input("Enter the first number:")) num2=int(input("Enter the second number:")) print "num1:",num1,"num2:", num2 num1,num2=num2,num1 print "After swap: num1:",num1,"num2:", num2 |
Explanation:
Here num1, num2 acts as a tuple. Since tuples are mutable, the above assignment works perfectly well
Output:
1 2 3 4 |
Enter the first number:8 Enter the second number:99 num1: 8 num2: 99 After swap: num1: 99 num2: 8 |
Question:
A robot moves in a plane starting from the original point (0,0). The robot can move toward UP, DOWN, LEFT and RIGHT with a given steps. The trace of robot movement is shown as the following:
UP 5
DOWN 3
LEFT 3
RIGHT 2
The numbers after the direction are steps. Please write a program to compute the distance from current position after a sequence of movement and original point. If the distance is a float, then just print the nearest integer.
Example:
If the following tuples are given as input to the program:
UP 5
DOWN 3
LEFT 3
RIGHT 2
Then, the output of the program should be:2
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import math pos = [0,0] while True: s = raw_input() if not s: break movement = s.split(" ") direction = movement[0] steps = int(movement[1]) if direction=="UP": pos[0]+=steps elif direction=="DOWN": pos[0]-=steps elif direction=="LEFT": pos[1]-=steps elif direction=="RIGHT": pos[1]+=steps else: pass print int(round(math.sqrt(pos[1]**2+pos[0]**2))) |
Explanation:
The distance formula is derived from the Pythagorean theorem. To find the distance between two points (x1,y1) and (x2,y2), all that you need to do is use the coordinates of these ordered pairs and apply the formula d=√{(x2−x1)2+(y2−y1)2}.This formula is used to find the distance.
Output:
1 2 3 4 5 6 |
UP 20 RIGHT 70 UP 20 Left 60 81 |