Skip to content

Instantly share code, notes, and snippets.

View Templarrr's full-sized avatar

Michael Odintsov Templarrr

  • NeoCybernetica
  • Ukraine
View GitHub Profile
@Templarrr
Templarrr / estimate_array_ram_usage.py
Created September 24, 2020 13:41
A couple of methods to estimate RAM usage for numpy and scipy sparse matrixes BEFORE their creation (quick and dirty, overhead isn't counted)
import numpy as np
def estimate_numpy_array_memory_size(shape, dtype):
size = np.product(shape)
return size * dtype.itemsize
def estimate_coo_matrix_memory_size(shape, dtype, nnz):
# each nonzero element has entries in data with corresponding dtype + entries in col and row
row_count = shape[0]
col_count = shape[1] if len(shape) > 1 else 1
@Templarrr
Templarrr / rgb_to_temperature.py
Created September 24, 2020 10:51
RGB to temperature and temperature to RGB conversions
import numpy as np
import scipy.constants
# These can differ depending on the exact hardware and setting, but given that
# we do approximation anyway - this shouldn't be a problem
red_wavelength = 570 * 10 ** -9
green_wavelength = 540 * 10 ** -9
blue_wavelength = 430 * 10 ** -9
h = scipy.constants.Planck
@Templarrr
Templarrr / sol.py
Created July 20, 2018 10:23
Solution NN
import numpy as np
def sigmoid(x):
return 1 / (1 + np.exp(-x))
def sigmoid_derivative(output):
return output * (1 - output)
@Templarrr
Templarrr / max_floor_new2.py
Created September 27, 2017 20:35
max_floor_new2.py
def max_floor_new2(eggs_count, trials):
if trials == 1:
return 1
elif eggs_count == 1:
return trials
elif eggs_count >= trials:
return 2 ** trials - 1
else:
binomial = 1
sum = 0
@Templarrr
Templarrr / max_floor_new.py
Created September 27, 2017 18:58
max_floor_new.py
import numpy as np
from scipy.ndimage.interpolation import shift
import time
def max_floor_new(eggs_count, trials):
if trials == 1:
return 1
elif eggs_count == 1:
return trials
@Templarrr
Templarrr / eggs.py
Created September 27, 2017 10:56
eggs and floors
def max_floor(eggs_count, trials):
if trials == 1:
return 1
elif eggs_count == 1:
return trials
else:
return max_floor(eggs_count-1, trials-1) + max_floor(eggs_count, trials-1) + 1
print max_floor(eggs_count=2, trials=14) # 105
print max_floor(eggs_count=7, trials=20) # 137979
C:\Users\templ\books\Scripts\python.exe C:/Users/templ/PycharmProjects/books/playground.py
Fiction : 4746
Speculative fiction : 4313
Science Fiction : 2870
Novel : 2463
Fantasy : 2413
Children's literature : 2121
Mystery : 1396
Young adult literature : 825
Suspense : 765
# coding=utf-8
inp = u'аослп'
def anagram(inp):
if len(inp) <= 1:
return [inp]
else:
results = []
@Templarrr
Templarrr / heartpwn.py
Created October 9, 2016 16:31
heartpwn grabber
import requests
from HTMLParser import HTMLParser
class MyHTMLParser(HTMLParser):
def __init__(self):
HTMLParser.__init__(self)
self.cards = {}
def reset_cards(self):
import os
os.environ['DATAROBOT_ENDPOINT'] = 'http://localhost/api/v2'
os.environ['DATAROBOT_USERNAME'] = 'test@test.ru'
os.environ['DATAROBOT_PASSWORD'] = 'testing123'
from datarobot_sdk import Project
from time import sleep
query_interval_in_seconds = 10
path_to_train_file = '/home/modintsov/workspace/shrink/tmp/mbtest-datasets/559a516366fca05b806c92bf/2006_2010_Draft_Tools_for_is50p_414x5.csv'
def wait_for_project_queue_finished(project):