Remove Multiple Unused Imports and Variable

This commit is contained in:
ParthS007 2018-10-18 02:58:57 +05:30
parent 765a3267fc
commit 0856a61859
22 changed files with 34 additions and 50 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ __pycache__/
*.so *.so
# Distribution / packaging # Distribution / packaging
.vscode/
.Python .Python
env/ env/
build/ build/

View File

@ -1,3 +0,0 @@
{
"python.pythonPath": "/usr/bin/python3"
}

View File

@ -1,7 +1,7 @@
import math
import numpy import numpy
def LUDecompose (table): #table that contains our data def LUDecompose (table):
#table that contains our data
#table has to be a square array so we need to check first #table has to be a square array so we need to check first
rows,columns=numpy.shape(table) rows,columns=numpy.shape(table)
L=numpy.zeros((rows,columns)) L=numpy.zeros((rows,columns))
@ -31,4 +31,4 @@ def LUDecompose (table): #table that contains our data
matrix =numpy.array([[2,-2,1],[0,1,2],[5,3,1]]) matrix =numpy.array([[2,-2,1],[0,1,2],[5,3,1]])
L,U = LUDecompose(matrix) L,U = LUDecompose(matrix)
print(L) print(L)
print(U) print(U)

View File

@ -3,16 +3,14 @@
from sympy import diff from sympy import diff
from decimal import Decimal from decimal import Decimal
from math import sin, cos, exp
def NewtonRaphson(func, a): def NewtonRaphson(func, a):
''' Finds root from the point 'a' onwards by Newton-Raphson method ''' ''' Finds root from the point 'a' onwards by Newton-Raphson method '''
while True: while True:
x = a
c = Decimal(a) - ( Decimal(eval(func)) / Decimal(eval(str(diff(func)))) ) c = Decimal(a) - ( Decimal(eval(func)) / Decimal(eval(str(diff(func)))) )
x = c
a = c a = c
# This number dictates the accuracy of the answer # This number dictates the accuracy of the answer
if abs(eval(func)) < 10**-15: if abs(eval(func)) < 10**-15:
return c return c

View File

@ -1,8 +1,6 @@
from __future__ import print_function from __future__ import print_function
import heapq import heapq
import numpy as np import numpy as np
import math
import copy
try: try:
xrange # Python 2 xrange # Python 2

View File

@ -140,7 +140,7 @@ from collections import deque
def topo(G, ind=None, Q=[1]): def topo(G, ind=None, Q=[1]):
if ind == None: if ind is None:
ind = [0] * (len(G) + 1) # SInce oth Index is ignored ind = [0] * (len(G) + 1) # SInce oth Index is ignored
for u in G: for u in G:
for v in G[u]: for v in G[u]:

View File

@ -3,7 +3,6 @@ a^2+b^2=c^2
Given N, Check if there exists any Pythagorean triplet for which a+b+c=N Given N, Check if there exists any Pythagorean triplet for which a+b+c=N
Find maximum possible value of product of a,b,c among all such Pythagorean triplets, If there is no such Pythagorean triplet print -1.""" Find maximum possible value of product of a,b,c among all such Pythagorean triplets, If there is no such Pythagorean triplet print -1."""
#!/bin/python3 #!/bin/python3
import sys
product=-1 product=-1
d=0 d=0

View File

@ -1,5 +1,5 @@
from __future__ import print_function from __future__ import print_function
from math import factorial, ceil from math import factorial
def lattice_paths(n): def lattice_paths(n):
n = 2*n #middle entry of odd rows starting at row 3 is the solution for n = 1, 2, 3,... n = 2*n #middle entry of odd rows starting at row 3 is the solution for n = 1, 2, 3,...

View File

@ -68,8 +68,8 @@ def getRandomKey():
while True: while True:
keyA = random.randint(2, len(SYMBOLS)) keyA = random.randint(2, len(SYMBOLS))
keyB = random.randint(2, len(SYMBOLS)) keyB = random.randint(2, len(SYMBOLS))
if cryptoMath.gcd(keyA, len(SYMBOLS)) == 1: if cryptoMath.gcd(keyA, len(SYMBOLS)) == 1:
return keyA * len(SYMBOLS) + keyB return keyA * len(SYMBOLS) + keyB
if __name__ == '__main__': if __name__ == '__main__':
import doctest import doctest

View File

@ -24,7 +24,7 @@ class LinkedList:
temp = self.head temp = self.head
self.head = self.head.next # oldHead <--> 2ndElement(head) self.head = self.head.next # oldHead <--> 2ndElement(head)
self.head.previous = None # oldHead --> 2ndElement(head) nothing pointing at it so the old head will be removed self.head.previous = None # oldHead --> 2ndElement(head) nothing pointing at it so the old head will be removed
if(self.head == None): if(self.head is None):
self.tail = None self.tail = None
return temp return temp
@ -58,7 +58,7 @@ class LinkedList:
current.next.previous = current.previous # 1 <--> 3 current.next.previous = current.previous # 1 <--> 3
def isEmpty(self): #Will return True if the list is empty def isEmpty(self): #Will return True if the list is empty
return(self.head == None) return(self.head is None)
def display(self): #Prints contents of the list def display(self): #Prints contents of the list
current = self.head current = self.head

View File

@ -19,4 +19,4 @@ class LinkedList:
return item return item
def is_empty(self): def is_empty(self):
return self.head == None return self.head is None

View File

@ -67,3 +67,4 @@ class Linked_List:
current = next_node current = next_node
# Return prev in order to put the head at the end # Return prev in order to put the head at the end
Head = prev Head = prev
return Head

View File

@ -1,5 +1,5 @@
import tensorflow as tf import tensorflow as tf
from random import choice, shuffle from random import shuffle
from numpy import array from numpy import array

View File

@ -59,7 +59,6 @@ def sum_of_square_error(data_x, data_y, len_data, theta):
:param theta : contains the feature vector :param theta : contains the feature vector
:return : sum of square error computed from given feature's :return : sum of square error computed from given feature's
""" """
error = 0.0
prod = np.dot(theta, data_x.transpose()) prod = np.dot(theta, data_x.transpose())
prod -= data_y.transpose() prod -= data_y.transpose()
sum_elem = np.sum(np.square(prod)) sum_elem = np.sum(np.square(prod))

View File

@ -28,9 +28,8 @@ Game-Of-Life Rules:
comes a live cell, as if by reproduction. comes a live cell, as if by reproduction.
''' '''
import numpy as np import numpy as np
import random, time, sys import random, sys
from matplotlib import pyplot as plt from matplotlib import pyplot as plt
import matplotlib.animation as animation
from matplotlib.colors import ListedColormap from matplotlib.colors import ListedColormap
usage_doc='Usage of script: script_nama <size_of_canvas:int>' usage_doc='Usage of script: script_nama <size_of_canvas:int>'

View File

@ -290,7 +290,7 @@ def goldbach(number):
while (i < lenPN and loop): while (i < lenPN and loop):
j = i+1; j = i+1
while (j < lenPN and loop): while (j < lenPN and loop):
@ -300,9 +300,8 @@ def goldbach(number):
ans.append(primeNumbers[i]) ans.append(primeNumbers[i])
ans.append(primeNumbers[j]) ans.append(primeNumbers[j])
j += 1; j += 1
i += 1 i += 1
# precondition # precondition

View File

@ -2,7 +2,6 @@
This is pure python implementation of interpolation search algorithm This is pure python implementation of interpolation search algorithm
""" """
from __future__ import print_function from __future__ import print_function
import bisect
try: try:
raw_input # Python 2 raw_input # Python 2

View File

@ -1,8 +1,5 @@
import collections
import sys
import random import random
import time
import math
""" """
A python implementation of the quick select algorithm, which is efficient for calculating the value that would appear in the index of a list if it would be sorted, even if it is not already sorted A python implementation of the quick select algorithm, which is efficient for calculating the value that would appear in the index of a list if it would be sorted, even if it is not already sorted
https://en.wikipedia.org/wiki/Quickselect https://en.wikipedia.org/wiki/Quickselect
@ -25,23 +22,23 @@ def _partition(data, pivot):
equal.append(element) equal.append(element)
return less, equal, greater return less, equal, greater
def quickSelect(list, k): def quickSelect(list, k):
#k = len(list) // 2 when trying to find the median (index that value would be when list is sorted) #k = len(list) // 2 when trying to find the median (index that value would be when list is sorted)
smaller = [] smaller = []
larger = [] larger = []
pivot = random.randint(0, len(list) - 1) pivot = random.randint(0, len(list) - 1)
pivot = list[pivot] pivot = list[pivot]
count = 0 count = 0
smaller, equal, larger =_partition(list, pivot) smaller, equal, larger =_partition(list, pivot)
count = len(equal) count = len(equal)
m = len(smaller) m = len(smaller)
#k is the pivot #k is the pivot
if m <= k < m + count: if m <= k < m + count:
return pivot return pivot
# must be in smaller # must be in smaller
elif m > k: elif m > k:
return quickSelect(smaller, k) return quickSelect(smaller, k)
#must be in larger #must be in larger
else: else:
return quickSelect(larger, k - (m + count)) return quickSelect(larger, k - (m + count))

View File

@ -4,7 +4,6 @@
# Sort large text files in a minimum amount of memory # Sort large text files in a minimum amount of memory
# #
import os import os
import sys
import argparse import argparse
class FileSplitter(object): class FileSplitter(object):

View File

@ -2,7 +2,6 @@ from __future__ import print_function
from random import randint from random import randint
from tempfile import TemporaryFile from tempfile import TemporaryFile
import numpy as np import numpy as np
import math

View File

@ -11,12 +11,12 @@ class node():
def insert(self,val): def insert(self,val):
if self.val: if self.val:
if val < self.val: if val < self.val:
if self.left == None: if self.left is None:
self.left = node(val) self.left = node(val)
else: else:
self.left.insert(val) self.left.insert(val)
elif val > self.val: elif val > self.val:
if self.right == None: if self.right is None:
self.right = node(val) self.right = node(val)
else: else:
self.right.insert(val) self.right.insert(val)

View File

@ -68,7 +68,6 @@ def assemble_transformation(ops, i, j):
return seq return seq
if __name__ == '__main__': if __name__ == '__main__':
from time import sleep
_, operations = compute_transform_tables('Python', 'Algorithms', -1, 1, 2, 2) _, operations = compute_transform_tables('Python', 'Algorithms', -1, 1, 2, 2)
m = len(operations) m = len(operations)