def get_subrectangles(m, n): m, n = (max(m, n), min(m, n)) num_rectangles = 0 if m <= 0 or n <= 0: num_rectangles = 0 elif m == 1: num_rectangles = sum([math.ceil(n / (n - j)) for j in xrange(n)]) elif n == 1: num_rectangles = sum([math.ciel(m / (m - i)) for i in xrange(m)]) else: # number of subrectangles in (m * n) = # number of unique unit rectangles in this level: m + n - 1 # number of row-wise: m # number of col-wise: n # parts = ( # number of subrectangles in smaller problem: get_subrectangles(m - 1, n - 1) get_subrectangles(m - 1, n - 1), # number of unique unit rectangles in this level: m + n - 1 m + n - 1, # number of new subrectangles formed by (m * (n - j)) for j = [0, n) m * sum([math.ceil(n / (n - j)) for j in xrange(n)]), # number of new subrectangles formed by (n * (m - i)) for i = [0, m) sum([math.ciel(m / (m - i)) for i in xrange(m)]), # number of new subrectangles sized (m - 1, n - 1): 3 3, ) num_rectangles = sum(parts) return num_rectangles
def event2LED(events): if not events: return None, None else: ledColor = np.zeros(48) ledEvent = [''] * 48 for event in events: start = parse(event['start'].get('dateTime', event['start'].get('dateTime'))) startTime = start.hour + start.minute / 60. end = parse(event['end'].get('dateTime', event['start'].get('dateTime'))) endTime = end.hour + end.minute / 60. # print (startTime, endTime) color = event['colorId'] if 'colorId' in event.keys() else 1 if startTime < endTime: for x in range(int(math.floor(startTime * 2)), int(math.ceil(endTime * 2))): ledColor[x] = color ledEvent[x] = event['summary'] else: for x in range(int(math.floor(startTime * 2)), 48): ledColor[x] = color ledEvent[x] = event['summary'] for y in range(0, int(math.ciel(endTime * 2))): ledColor[y] = color ledEvent[y] = event['summary'] return ledColor, ledEvent
def fish_eye_transofrm(self, point, screen_dist): p_x, p_y, _ = point c_x, c_y, c_z = self.screen_center dx, dy = abs(c_x - p_x), abs(c_y - p_y) theta = math.atan(dy / dx) R = alg.calc_effective_radius(k,theta,screen_dist) n_x = R*math.cos(theta)/self.pixel_size + c_x n_y = R*math.sin(theta)/self.pixel_size + c_y bl_x, bl_w, _ = bottom_left ni, nj = math.ceil((n_x - bl_x) / self.pixel_size), math.ciel((n_y - bl_y) / self.pixel_size)
def median_group_views(self): ''' Get the median number of views in this group ''' medianIndex = len(self.videos) / 2 median = int(medianIndex) if ((medianIndex % 2) == 1): median = int((int(math.floor(medianIndex)) + int(math.ciel(medianIndex))) / 2) return self.get_video_views(self.videos[median])
def spacy_parse_chunks(text, nlp, parsefuncs=list(), chunk_size=10): '''Parses document in sentence chunks to reduce memory use. ''' # sentence is smallest unit spacy analyzes # multiply by two since split includes punctuation too sents = re.split(r'[\?\!\.]', text) n_chunks = math.ciel(len(sents)/(chunk_size*2)) sent_chunks = [sents[i*chunk_size*2:(i+1)*chunk_size*2] for i in range(n_chunks)] for sent_chunk in sent_chunks: subdoc = nlp(''.join(sent_chunk))
def hunger_games(tensors, k, alpha): """Takes a layer of a neural network and applies the tanh activation function; it then applies KATE style competition and returns the result""" with tf.variable_scope("KATE Competition"): tan = tf.tanh(tensors, name="K-Activated") pos = zero_if_false(tf.greater(tan, 0), tan) neg = zero_if_false(tf.less(tan, 0), tan) pos_adder = tf.reduce_sum(pos) neg_adder = tf.reduce_sum(neg) pos_val, _ = tf.nn.top_k(pos, math.ciel(k / 2)) + alpha * pos_adder neg_val, _ = -tf.nn.top_k(-neg, math.floor(k / 2)) + alpha * neg_adder return tf.concat([pos_val, neg_val], 0)
def median(alist): """Numpy can perform this task. But that is the only numpy functionality we need. So I createed it and removed the dependency. Args: :list alist: a list of float compatible values. Return: :float median: median of `alist` """ alist.sort() n = len(alist) mid = math.ciel(n/2) if (n % 2) == 0: mid2 = mid - 1 return (alist[mid] + alist[mid2])/2.0 return alist[mid]
def get(self, search): firstString = [] secondString = [] thirdString = [] first = True second = True for i in range(0, len(search)): if search[i] == ":": first = False continue if first: firstString.append(search[i]) elif not first: if search[i] == ":": second = False if second: if search[i] == "_": secondString.append(" ") continue secondString.append(search[i]) elif not second: thirdString.append(search[i]) f = ''.join(firstString) # 'all', 'author', or 'title' t = ''.join(thirdString) t = int(t) # page number print(f) if len(secondString) > 0: s = ''.join(secondString) # name of title or name of author print(s) if f == "author": data = BookModel.query.filter_by(author=s).all() newdata =[] of = math.ciel(len(data)/page_size) # total number of pages page = t # page number requested by frontend for book in range(page*page_size, (page+1)*page_size): newdata.append(book.json_page(page, of)) return {"books": [book.json() for book in BookModel.query.filter_by(author=s).all()]} #used to be return {"books": [book.json() for book in BookModel.query.filter_by(author=s).all()]} elif f == "title": return {"books": [book.json() for book in BookModel.query.filter_by(title=s).all()]} else: return{"message": "error, can only search by title or author: /booklist/author:Bill_Shakespeare"} elif search != "all": return {"message": "Please enter booklist/all or booklist/author:xxx or booklist/title:xxx"} return {"books": [book.json() for book in BookModel.query.all()]}
def payouts(players, winningPlayer): favor, multiplier = odds(players[1], players[2]) if winningPlayer == 1: winners = players[1] losers = players[2] else: winners = players[2] losers = players[1] for i in winners: if favor == 1 and winners[i][0] != "NA": if winningPlayer == 1: userData = collection.find({"username": winners[i][0]}) winnerData = [{ "username": winners[i][0], "amount": (int(userData['amount']) + (math.ciel(float(winners[i][1]) / multiplier))) }] collection.replace_one(winnerData, True) else: userData = collection.find({"username": winners[i][0]}) winnerData = [{ "username": winners[i][0], "amount": (int(userData['amount']) + (math.ciel(float(winners[i][1]) * multiplier))) }] collection.replace_one(winnerData, True) elif winners[i][0] != "NA": if winningPlayer == 1: userData = collection.find({"username": winners[i][0]}) winnerData = [{ "username": winners[i][0], "amount": (int(userData['amount']) + (math.ciel(float(winners[i][1]) * multiplier))) }] collection.replace_one(winnerData, True) else: userData = collection.find({"username": winners[i][0]}) winnerData = [{ "username": winners[i][0], "amount": (int(userData['amount']) + (math.ciel(float(winners[i][1]) / multiplier))) }] collection.replace_one(winnerData, True) for i in losers: if losers[i][0] != "NA": userData = collection.find({"username": losers[i][0]}) loserData = [{ "username": losers[i][0], "amount": (int(userData['amount']) - math.ciel(float(winners[i][1]))) }] collection.replace_one(loserData, True)
import subprocess import sys import math sys.path.append('/home/ubuntu/TOOLS/Scripts/utility') from job_manager import job_manager fn = sys.argv[1] th = sys.argv[2] # create sub_files to process lc_info = subprocess.check_output('wc -l ' + fn, shell=True) fh = open(fn, 'r') lc = lc_info.split() line_split = math.ciel(float(lc[0])/float(th)) cur = 1 fct = 1 flist = [] cur_file = fn + str(fct) + 'split' out_pre = 'Gene_metrics' + str(fct) out = open(cur_file, 'w') job_list = [] cmd = '/home/ubuntu/TOOLS/dropseq/2_calc_mean_variance_bin.py ' job_list.append(cmd + cur_file + ' ' + out_pre + ' 0') head = next(fh) # out.write(head) for line in fh: if cur > line_split: out.close() fct += 1
def __init__(self, length=None): if length: length = math.ciel(length//8) # Convert bits to bytes. super().__init__(length)
def time(n): steps = 3 + 2*math.ciel(n/5)
(175, 10917280, <class 'int'>) >>> lng=5422222222222222222222222222222222222222222222222222 >>> lng,id(lng),type(lng) (5422222222222222222222222222222222222222222222222222, 139934208108128, <class 'int'>) >>> var=-5 >>> var -5 >>> abs(var) 5 >>> var=-0 >>> math.ciel(var) Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'math' is not defined >>> import math >>> math.ciel(var) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'math' has no attribute 'ciel' >>> math.ceil(var) 0 >>> math.floor(var) 0 >>> var=56.89 >>> math.ceil(var) 57 >>> math.floor(var) 56 >>> math.expl(l) Traceback (most recent call last): File "<stdin>", line 1, in <module>
import subprocess import sys import math sys.path.append('/home/ubuntu/TOOLS/Scripts/utility') from job_manager import job_manager fn = sys.argv[1] th = sys.argv[2] # create sub_files to process lc_info = subprocess.check_output('wc -l ' + fn, shell=True) fh = open(fn, 'r') lc = lc_info.split() line_split = math.ciel(float(lc[0]) / float(th)) cur = 1 fct = 1 flist = [] cur_file = fn + str(fct) + 'split' out_pre = 'Gene_metrics' + str(fct) out = open(cur_file, 'w') job_list = [] cmd = '/home/ubuntu/TOOLS/dropseq/2_calc_mean_variance_bin.py ' job_list.append(cmd + cur_file + ' ' + out_pre + ' 0') head = next(fh) # out.write(head) for line in fh: if cur > line_split: out.close() fct += 1
Type "help", "copyright", "credits" or "license()" for more information. >>> import math >>> >>> x = sqrt(25) Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> x = sqrt(25) NameError: name 'sqrt' is not defined >>> x = math.sqrt(25) >>> x 5.0 >>> print(math.floor) <built-in function floor> >>> print(math.floor(4.9)) 4 >>> print(math.ciel(4.9)) Traceback (most recent call last): File "<pyshell#7>", line 1, in <module> print(math.ciel(4.9)) AttributeError: module 'math' has no attribute 'ciel' >>> print(math.ceil(4.9)) 5 >>> print(math.ceil(4.1)) 5 >>> print() >>> print(math.pi) 3.141592653589793 >>> print(math.e) 2.718281828459045 >>> print(math.pow(11,6))