This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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))) |
NewerOlder