Skip to content

Instantly share code, notes, and snippets.

View sameerg07's full-sized avatar

Sameer Gadicherla sameerg07

View GitHub Profile
@sameerg07
sameerg07 / sort_key.py
Created June 13, 2021 07:40
sort list of tuples with key
import ast,sys
input_str = input()
input_list = ast.literal_eval(input_str)
sorting_choice = input()
# Your code goes here
print(sorted(input_list,key=lambda x: x[int(sorting_choice)-1]))
@sameerg07
sameerg07 / n_gradient_descent.py
Created June 7, 2021 10:24
gradient descent for more than 1 independent variable
import numpy as np
# Theta is the vector representing coefficients (intercept, area, bedrooms)
theta = np.matrix(np.array([0,0,0]))
alpha = 0.01
iterations = 1000
# define cost function
# takes in theta (current values of coefficients b0, b1, b2), X and y
@sameerg07
sameerg07 / gradient_descent.py
Created June 7, 2021 09:57
Manual Gradient descent for given X and y with starting m and c values for an equation y= mX + c
# Takes in X, y, current m and c (both initialised to 0), num_iterations, learning rate
# returns gradient at current m and c for each pair of m and c
def gradient(X, y, m_current=0, c_current=0, iters=1000, learning_rate=0.01):
N = float(len(y))
gd_df = pd.DataFrame( columns = ['m_current', 'c_current','cost'])
for i in range(iters):
y_pred = (m_current * X) + c_current
cost = sum([data**2 for data in (y-y_pred)]) / N
m_gradient = -(2/N) * sum(X * (y - y_pred))
@sameerg07
sameerg07 / second_largest.py
Created June 4, 2021 04:39
second largest number in a list
# Read the input list
import ast,sys
input_str = sys.stdin.read()
input_list = ast.literal_eval(input_str)
# Write your code here
try:
print(list(set(sorted(input_list)))[-2])
except:
print("not present")
@sameerg07
sameerg07 / caps_word.py
Created June 4, 2021 04:29
Convert first letter to capital in each word of a string python
# Read the input string
input_string = input()
# Write your code here
nl = input_string.split(" ")
for i in range(len(nl)):
nl[i] = nl[i][0].upper() + nl[i][1:]
print(' '.join(nl))
@sameerg07
sameerg07 / armstrong.py
Created June 4, 2021 03:52
Armstrong Number check in python
n=int(input())
# 153=1^3+5^3+3^3
def armstrong(n):
nums = [int(x)**3 for x in str(n)] ## separate the numbers and cube
if sum(nums) == n:
return True
else:
return False
print(armstrong(n))
@sameerg07
sameerg07 / prime.py
Created June 4, 2021 03:49
Check if a number is prime in python
n=int(input())
#write your code here
if n%2 == 0 and n!=2 and n!=0:
print("number entered is not prime")
else:
print("number entered is prime")
@sameerg07
sameerg07 / fibonacci.py
Created June 4, 2021 03:41
fibonacci series generation for N numbers
def fibonacci(n):
if n == 1 or n == 2:
return n-1
else:
return fibonacci(n-1) + fibonacci(n-2)
n = int(input())
i = 1
while i <= n:
print(fibonacci(i))
from keras.models import load_model
from keras.preprocessing.image import ImageDataGenerator
from keras.models import Sequential
from keras.layers import Conv2D, MaxPooling2D
from keras.layers import Activation, Dropout, Flatten, Dense
from keras import backend as K
import cv2
import numpy as np
model = Sequential()
model.add(Conv2D(32, (3, 3), input_shape=input_shape))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))
model.add(Conv2D(32, (3, 3)))
model.add(Activation('relu'))
model.add(MaxPooling2D(pool_size=(2, 2)))