content stringlengths 35 416k | sha1 stringlengths 40 40 | id int64 0 710k |
|---|---|---|
def get_features(*functions):
"""合并多个 list,主要用途(合并多种不同的数据集进行训练)"""
features = []
for i in functions:
features.extend(i)
return features | 643c077985a69910f7d69d1db3c8b62a94de94c2 | 17,975 |
def num_divisors_from_fac(fac):
"""
Given a prime factorization fac (a dictionary of the form prime :
exponent), returns the number of divisors of the factorized number.
"""
acc = 1
for p in fac:
acc *= fac[p] + 1
return acc | 776991357a5f198f156e74657b557cd889de06b3 | 17,976 |
def get_list_mode(request):
"""Get the current display mode for the dashboard."""
list_mode = request.args.get('list')
if (list_mode != 'true'):
list_mode = None
return list_mode | ceb58b9aba64d96a4675e2ef821deadc26110af2 | 17,977 |
import math
def cost(a,b,c,e,f,p_min,p):
"""cost: fuel cost based on "standard" parameters
(with valve-point loading effect)
"""
return a + b*p + c*p*p + abs(e*math.sin(f*(p_min-p))) | c0acc4e8820e5ce354cee411afc1a121c07757bc | 17,979 |
import sys
import json
def get_deposit_account(cbpro_client):
""" Gets ID of account's ACH bank account (assumes there's only one)
Params:
- None
Return:
- account: dict
{
{
"allow_buy": bool,
"allow_deposit": bool,
"allow_sell": b... | 124ae6857833e96f67d113a3919aacc9a1c1c442 | 17,980 |
def safer_eval(some_string):
"""
Not full-proof, but taking advice from:
https://nedbatchelder.com/blog/201206/eval_really_is_dangerous.html
"""
if "__" in some_string or "import" in some_string:
raise Exception("string to eval looks suspicious")
return eval(some_string, {'__builtins__'... | 6a392d48fe66b3c6397e0970a8e854b26326c188 | 17,981 |
def xgcd(x, y):
"""Extended GCD
Args:
x (integer)
y (integer)
Returns:
(gcd, x, y) where gcd is the greatest common divisor of a and b.
The numbers x, y are such that gcd = ax + by.
"""
prev_a = 1
a = 0
prev_b = 0
b = 1
while y != 0:
q =... | f7d326302042880f72b9e70b0ea66890b00a093d | 17,982 |
def __remove_emojies(post_tokenized):
"""It deletes emojies from a post.
Args:
tokens(list): the tokenized target post.
Returns:
list: the tokenized target post without any emoji.
"""
new_post_tokenized = []
for word in post_tokenized:
try:
str(word)
... | b56edbec102ef5a259a744dc9787991986cc9af8 | 17,983 |
import os
def get_template(name):
"""
Get a template name.
@param name template name
@return content
"""
this = os.path.dirname(name)
tm = os.path.join(this, name)
if not os.path.exists(tm):
raise FileNotFoundError("Unable to find template '{0}'.".format(na... | 07b1f40fbbd6bbf488b12514308f7bc482c13c52 | 17,985 |
def chunk(mylist, chunksize):
"""
Args:
mylist: array
chunksize: int
Returns:
list of chunks of an array len chunksize (last chunk is less)
"""
N = len(mylist)
chunks = list(range(0, N, chunksize)) + [N]
return [mylist[i:j] for i, j in zip(chunks[:-1], chunks[1:])] | 69cc8aa812c989c63dae4c444ee132c54a861fa4 | 17,986 |
def is_rejected_with_high_vaf(vaf, status, vaf_th):
"""Check if SNV is rejected with vaf over threshold.
Args:
vaf: vaf of the SNV.
vaf_th: vaf threshold.
status: reject/pass status of SNV.
Returns:
True if rejected, False otherwise
"""
if vaf > vaf_th and status =... | 9b048c9a2d562f50cbfc4af56d4c33189d95f00e | 17,987 |
import os
def fixture_path(*path: str) -> str:
"""
Get fixture path for this test folder.
"""
basedir = os.path.realpath(os.path.dirname(__file__))
filepath = os.path.join(basedir, "fixtures", *path)
return filepath | e46438483c4a681ea547a46e4bbe5a3105d7e456 | 17,990 |
def _Backward3a_v_Ph(P, h):
"""Backward equation for region 3a, v=f(P,h)
>>> "%.12f" % _Backward3a_v_Ph(20,1700)
'0.001749903962'
>>> "%.12f" % _Backward3a_v_Ph(100,2100)
'0.001676229776'
"""
I=[-12, -12, -12, -12, -10, -10, -10, -8, -8, -6, -6, -6, -4, -4, -3, -2, -2, -1, -1, -1, -1, 0... | 3417154afacd8d582bce1be94a306ddc3eed11d2 | 17,992 |
def apply(f, *args, **kwargs):
"""Apply a function to arguments.
Parameters
----------
f : callable
The function to call.
*args, **kwargs
**kwargs
Arguments to feed to the callable.
Returns
-------
a : any
The result of ``f(*args, **kwargs)``
Examples
... | 55850e03ce6078e17c92197cbece14a0ff99c0fd | 17,993 |
def first_word_complex(text: str) -> str:
"""
returns the first word in a given text.
"""
l = []
for x in text:
if x.isalpha() or x == "'":
l.append(x)
else:
l.append(" ")
w = "".join(l)
result = w.split()
return result[0] | 57c9558ad7bedfa31fbf1d14b4665b6d803175a7 | 17,995 |
def delete_from_list(head, tail, elem):
"""Delete an element from the list"""
if head is None or tail is None:
return -1, -1
if head.data == elem:
if head == tail:
head = tail = None
return -1, -1
curr = head
head = head.next
head.prev = None... | f8e4a62be7b196cd9159015d86d8ea19c4bcc909 | 17,998 |
def icingByteFcnPRB(c):
"""Return probability value of icing pixel.
Args:
c (unicode): Unicode icing pixel.
Returns:
int: Value of probability portion of icing pixel.
"""
return ord(c) & 0x07 | a19d9896ed1b932e44629cb0eff7268ffe8c6fee | 17,999 |
def replace_key_value(lookup, new_value, expected_dict):
"""
Replaces the value matching the key 'lookup' in the 'expected_dict' with
the new value 'new_value'.
"""
for key, value in expected_dict.items():
if lookup == key:
if isinstance(value, dict) and isinstance(new_value, dic... | 923cda5b8d2ba44749345d7d1adf907d4c5f3b23 | 18,002 |
from unittest.mock import Mock
def mock_group(test_state={}, n=0):
"""Mock a Tradfri group."""
default_state = {"state": False, "dimmer": 0}
state = {**default_state, **test_state}
mock_group = Mock(member_ids=[], observe=Mock(), **state)
mock_group.name = "tradfri_group_{}".format(n)
return... | 76664f2350838dbc8170aa3eeed972a7f7eda304 | 18,003 |
import numpy
def manual_bin(x, y, cuts):
"""
The function discretizes the x vector and then summarizes over the y vector
based on the discretization result.
Parameters:
x : A numeric vector to discretize without missing values,
e.g. numpy.nan or math.nan
y : A numeric vector with bi... | 3b0eb6dd2a352dcfb8d6b88fe7e15bef9baa6623 | 18,005 |
def bend(msg):
"""Returns the pitch bend value of a pitch bend message."""
return (msg[2] & 0x7F) << 7 | (msg[1] & 0x7F) | e3e19567a92fccb609b85fed42245727221e72f1 | 18,006 |
def AND_nobias(x1: int, x2: int) -> int:
"""
[summary] AND operator wituout bias term
Args:
x1 (int): 1st input for AND
x2 (int): 2nd input for AND
Returns:
int: result of AND operator
"""
(w1, w2, theta) = (0.5, 0.5, 0.7)
tmp = w1 * x1 + w2 * x2
if tmp <= thet... | e58a125a9c21233b8de7a044e5c0acdfdb29d1fa | 18,009 |
def get_edges(source_label, target_label,
edge_label, data=False):
"""Generate query for getting all the edges of the graph.
Parameters
----------
source_label : optional
Label of the source nodes to match
target_label : optional
Label of the target nodes to match
... | 39b47267a59c1409b4b32dab36033aec73296cf7 | 18,010 |
def precheck(atoms, i, j, Hs, As, Ds, fsc0):
"""
Check if two atoms are potential H bond partners, based on element and altloc
"""
ei, ej = atoms[i].element, atoms[j].element
altloc_i = atoms[i].parent().altloc
altloc_j = atoms[j].parent().altloc
resseq_i = atoms[i].parent().parent().resseq
resseq_j = a... | 1d1a721c85f8f920b097f71891280b7dd0b9cc77 | 18,012 |
def to_date(val):
"""Used if *val* is an instance of date."""
# NOTE: strftime's %Y is inconsistent between OSs; pads with 0 to 4 digits
# on Windows but doesn't pad on linux
# isoformat does not seemt to have that problem???
# return val.strftime("%Y-%m-%d")
return val.isoformat() | d67034c336b90de01e44e7beebb78c6cf4837f4b | 18,014 |
def filterReturnChar(string):
"""
过滤字符串中的"\r"字符
:param string:
:return: 过滤了"\r"的字符串
"""
return string.replace("\r", "") | fff1b39d8c837fc33e627d6ad2395eb05458517a | 18,016 |
def count_logistic(x):
"""Return value of a simple chaotic function."""
val = 3.9 * x * (1-x)
return val | 476c4efb391652e25443685f2660b82721c04e94 | 18,018 |
def check_learner_is_fitted(learner):
"""Return True if fitted and False otherwise"""
# Following scikit-learn's convention,
# fitted models have additional attributes ending with underscores.
# See: https://scikit-learn.org/dev/glossary.html#term-fitted
# Hence checking whether these exist is suffi... | 35e17e3d3a85fa9a65d77ed3be990fc060f87156 | 18,019 |
import torch
def load_latent_avg(checkpoint_path):
"""Load the latent average used by encoder."""
checkpoint = torch.load(checkpoint_path)
return checkpoint["latent_avg"] | 51ed354bd67ae78a6000dd5b60cab2e6a0cec413 | 18,020 |
import statistics
def Standard_Deviation(All_Results, pos):
"""Calculate the standard deviation to evaluate number of trial runs required."""
converted = [row[pos] for row in All_Results]
if isinstance(converted[0], list) == True:
converted = [row[1] for row in converted]
stdev = float(statis... | ddbbfa06c744014ced30ba7aadf9fe82bee984cb | 18,021 |
def parse_float(txt):
""" Returns None or parsed float value. """
# Floats must have decimal point
if txt.find('.') == -1:
return None
# Parse float using python's built-in converter
try:
return float(txt)
except ValueError:
return None | 2767faa591227ea8664a458c3bc55da51a0cb2f5 | 18,022 |
def makov_payne_correction(defect_cell, geometry, e_r, mk_1_1):
""" Makov-Payne correction
:param defect_cell: Cell object of the defect cell calculation
:param geometry: geometry of the host cell
:param e_r: relative permittivity
:param mk_1_1: Value of the first term of the Makov-Payne correction ... | 670755010e0bc2af35eea43563aae807db1d05d5 | 18,023 |
def method(a):
"""
:param a: 传参用于XXXX
:return: 返回一个XXX
"""
a+=1
return a | 22441f99679a765a11a64ab48897256502fed347 | 18,027 |
from pathlib import Path
from typing import List
import os
def recursive_dir_files(target_dir: Path) -> List[Path]:
"""return paths of files under target_dir, with prefix removed"""
prefix_len = len(target_dir.parts)
return [Path(*(Path(path) / f).parts[prefix_len:])
for path, _, files in os.walk(... | 264a3895d00334fad4b3b820b49564755e8bda67 | 18,028 |
import time
def retry(assertion_callable, retry_time=10, wait_between_tries=0.1, exception_to_retry=AssertionError):
"""Retry assertion callable in a loop"""
start = time.time()
while True:
try:
return assertion_callable()
except exception_to_retry as e:
if time.tim... | b8fdb7115d94da96823d6728c87ffce84d6f925c | 18,029 |
def swap(m, r1, r2):
""" Swap rows in forward elimination"""
temp = m[r1]
m[r1] = m[r2]
m[r2] = temp
return m | 4fcbde1aff552802a321f5c060a48d3961ba3a23 | 18,030 |
import os
def mkdir(dir_path):
""" Creates a directory.
Args:
dir_path: The path to create.
"""
return os.system("mkdir -p " + dir_path) | 91105f6cedbe36185bd53771135570be6eff37cf | 18,032 |
def deslugify(slug):
"""Turn a slug into human speak"""
return slug.replace('-', ' ').title() | d2a58a68d1759007068ca484146b2ca70fc88ce9 | 18,033 |
def to_bold_on_html(html_table:str) -> str:
"""100.0 in bold and background"""
html_tag = "<td>100</td>"
html_tag_replace = (
"""
<td>
<div style='text-align:center; background: #c0c0c0'>
<strong>100.0</strong>
</div>
</td>
"""
)
... | 462e820103f1cfcc3f7519f2978ad0e9435cd098 | 18,034 |
def compressive_failure(panel):
""""Return critical failure load for compressive failure"""
compressive = panel.area*panel.skin.material_properties['Suts']
return compressive | 55c199f47e77033a2c67f8514675c6845a9b90bc | 18,035 |
import requests
import json
def get_access_token(code, env):
""" Exchange the authorization code for an access token.
"""
token_url = env['tenant_url'] + '/oauth/token'
headers = {'Content-Type': 'application/json'}
body = {
'grant_type': env['grant_type'],
'client_id': env['client... | 9db7798ab63eff78d67d588a0e51e1289e26eb53 | 18,036 |
def construct_consensus_gp_as(has_rna, has_pb):
"""Dynamically generate an autosql file for consensus"""
consensus_gp_as = '''table bigCat
"bigCat gene models"
(
string chrom; "Reference sequence chromosome or scaffold"
uint chromStart; "Start position in chromosome"
uint chromEnd; ... | 04ad89609d68873792222d191c4259b4a35d1f33 | 18,038 |
from warnings import filters
def remove_punct(sentences):
"""
remove punctuation from a list of sentences
Args:
sentences (list): list of sentences
Returns:
sentences (list): list of senteces without punctuation
"""
for sentence in sentences:
sentence = sentence.tran... | e53d4c6bec96048e177f81ee0fe48afc17180860 | 18,039 |
def strftimeTranslate(txt: str) -> str:
"""
Translate strftime output to Turkish.
:param txt: strftime output.
:type txt: str
:rtype: str
"""
b = {"Jan": "Ocak", "Feb": "Şubat", "Mar": "Mart", "Apr": "Nisa", "May": "Mayıs", "Jun": "Haziran", "Jul": "Temmuz", "Aug": "Ağustos"... | 666f56d74fd8da39170e8fd9fd32e138f962aa4e | 18,041 |
import os
def get_user_login() -> str:
"""
Check user uid and return user name
:return str: user name
"""
return "root" if os.getuid() == 0 else os.getlogin() | 4da9b985d5b52759259da62c27f7fe76a984a635 | 18,042 |
from typing import List
import requests
def search(query: str, api_key: str) -> List:
"""Return search results."""
# ! to edit head to: https://cse.google.com/cse/all
params = {
"key": api_key,
#"cx": "'000281471148392423350:ymsqkb0dqs8"
"cx": "000281471148392423350:64fnnp-ny2w",... | b29961bbda063072d6dc8dedaef9cffe85ab6a2c | 18,044 |
def unpack_question_dimid(dimension_id):
"""Decompose the dimension id into unit, lesson and question id.
Returns:
A tuple unit_id, lesson_id, question_id.
unit_id and question_id are strings. lesson_id can be a string or
None.
"""
unit_id, lesson_id, question_id = dimension_id.... | 4133ec1ce5cd986b64c9af096931b9f2bf8cb123 | 18,046 |
import time
def timestamp2time( timestamp ):
""" convert a timestamp in yyyy.mm.dd.hh.mm.ss format to seconds for comparisons """
return time.mktime(time.strptime(timestamp,"%Y.%m.%d.%H.%M.%S")) | 7a2e9a6b51de0c9a4ebd69e1e0050bab4af064f9 | 18,048 |
import os
import sys
def load_whitelist(whitelist_file):
"""Load provided whitelist file."""
if not os.path.isfile(whitelist_file):
print('Error: Whitelist file not found.')
sys.exit(1)
whitelist = ['127.0.0.1']
with open(whitelist_file) as f:
for line in f.read().splitlines()... | 8781255f8bc357e5f3149723e12f2d7cbb50ab1e | 18,049 |
def dot_attention_score(key, query):
"""[B, Tk, D], [(Bs), B, Tq, D] -> [(Bs), B, Tq, Tk]"""
return query.matmul(key.transpose(1, 2)) | ec1f855d4d24d30bd3ab38943b25194887c7841c | 18,050 |
import six
def sorted_files(pdict):
"""
Returns the file_summary information sorted in reverse order based on duration
:param pdict: profile dict
:return: sorted list of file_summary dicts
"""
return sorted([v['file_summary'] for k, v in six.iteritems(pdict) if k != 'summary'],
... | 3135561bd68cdc0018c1b904f8a6b47dc4a96468 | 18,052 |
def get_axis_labels(df_list, key, kdims, vdims):
"""Generates the axis labels"""
try:
if df_list[key]["units"][df_list[key]["measurements"].index(kdims[1])]:
ylabel = "{} ({})".format(
kdims[1],
df_list[key]["units"][df_list[key]["measurements"].index(kdims[1]... | 5ac498879048ad50192d9106d177420e4574820e | 18,053 |
def all_subsets(s):
"""returns all the subsets included in this set."""
r = [set()]
for i in s:
for j in r[:]:
r.append(j | set([i]))
return r | d182ac9050cdb330fd18c5ce0ec63ceb8ac8bfc2 | 18,056 |
def create_link(n, d, suffix):
""" Creates a link from the name of the manpage.
This hasn't been tested extensively, as there are 10k+ links... but it's
worked for the handful that I tried?
"""
return (n, f"http://man7.org/linux/man-pages/man{d}/{n}.{d}{suffix}.html") | 6c5a98e634395874f09aa00dced37962a1fe5530 | 18,058 |
import json
def dump(key: str):
"""
Dumps all the JSON given the key
Parameters:
key (str): The key to dump
Returns:
data (dict): The JSON data
"""
data = {}
with open(f'./data/guild_{key}.json', 'r') as filein:
data = json.load(filein)
return ... | 6f243d5c09f4ff4a7e4ba4133b26089dfa37cac2 | 18,059 |
def str_set_of_candidates(candset, cand_names=None):
"""
Nicely format a set of candidates.
.. doctest::
>>> print(str_set_of_candidates({0, 1, 3, 2}))
{0, 1, 2, 3}
>>> print(str_set_of_candidates({0, 3, 1}, cand_names="abcde"))
{a, b, d}
Parameters
----------
... | 817592c964f8912585944a05e11606b4c4597721 | 18,063 |
from typing import List
from typing import Dict
def _jupyter_server_extension_paths() -> List[Dict[str, str]]:
"""
Function to declare Jupyter Server Extension Paths.
"""
# This comprehension actually works, but black can't handle it!
# return [ {"module": f"rsp_jupyter_extensions.{ext}"} for ext ... | dd3b364fdf08a796942223d1f46bc5ce4bb89150 | 18,064 |
def cli_submit_ci_job(apic, args):
"""Implement CLI command `submit-ci-project`.
"""
# pylint: disable=unused-argument
if args.repo_branch is None or args.repo_ref is None:
print('error: missing required arguments: --repo-branch or --repo-ref')
return 1
job_id = apic.submit_ci_job(ar... | 19abc8d9f7427c5f57b53ab341870ea0a4d6c2a5 | 18,065 |
def lorenz(amplitude: float, fwhm: float, x: int, x_0: float):
"""Model of the frequency response."""
return amplitude * ((fwhm / 2.0) ** 2) / ((x - x_0) ** 2 + (fwhm / 2.0) ** 2) | f7764c0103d8912a78e2f022e5a863310e0bf6b9 | 18,067 |
import os
def __is_cached__(file_name):
""" Determine which files should receive a cache-control header
Files that are not cached are:
- *.html (e.g. index.html, mobile.html)
- *.txt files
- the *.appcache file itself (although it's versioned with the
git_commit_short)
... | 959f2775e40cd33a0ca64d1a57e2aa5e2a7c3fe5 | 18,068 |
def find_anagrams(word, candidates):
"""
Return a list of word's anagrams from candidates
"""
same_removed = filter(lambda x: x.lower() != word.lower(), candidates)
return filter(lambda x: sorted(x.lower()) == sorted(word.lower()), same_removed) | 4c016e6febd9c1d4144b4756d43b5f596c33ec4f | 18,069 |
import subprocess
def get_file_contents(path, revision=None):
""" Return contents of a file in staged env or in some revision. """
revision = "" if revision is None else revision
r = subprocess.run(
["git", "show", "{r}:{p}".format(r=revision, p=path)],
stdout=subprocess.PIPE,
stde... | f23ad9238a8cb222c456cb98cb5d91de35896449 | 18,072 |
import time
def now():
"""
Returns:
Current formatted date-time.
"""
return time.strftime("%d.%m.%Y_%H:%M:%S") | 16401e97c10902b9a84a2868454421df83288b98 | 18,074 |
from typing import Dict
from typing import Any
def get_max_field_length(fields: Dict[str, Any]) -> int:
"""Get the length of the longest field in the dictionary ``fields``.
:param dict fields: A dictionary to search for the longest field.
"""
return max(map(len, fields)) | 62da7fd4fa8173bb641391100136122fde4c902c | 18,077 |
import math
def approximate_exp(num_terms=10):
"""Approximating exponential by adding
the inverse of n factorials."""
# returning the approximated exponential
return sum(1/math.factorial(num) for num in range(num_terms)) | d4c2cd7eaf000ca862051e64b22a0795c564ba26 | 18,078 |
import string
import os
def expand_path_vars(path):
"""
Expands a path variable which uses $-style substitutions.
:func:`os.path.expandvars` doesn't have any way to escape the substitutions
unlike :class:`string.Template`, so we have to do the substitutions manually.
"""
template = string.Tem... | a5969fcf118fba791a46636ec93cae9e09fe6a64 | 18,079 |
from typing import Tuple
from typing import Any
from typing import List
def _convert_record_to_object(class_: type, record: Tuple[Any], field_names: List[str]) -> Any:
"""
Convert a given record fetched from an SQL instance to a Python Object of given class_.
:param class_: Class type to convert the reco... | 3422fb51f959f1ead4f6af05bf750746358263bd | 18,080 |
def VOLTStoHEX(volts):
""" DAC: 1000.0 volts full scale (FFFF).
(for setting DAC output)
VOLTStoHEX(1000.0) => 'FFFF'
VOLTStoHEX( 900.0) => 'E665' """
return hex(int(volts * 65.535))[2:].upper() | 70418ab141f8e46e5068b56a3d3c9b2ecaa1d00e | 18,081 |
import os
def list_files(dirname, extension=None):
"""
List all files in directory `dirname`, option to filter on file extension
"""
f = []
for (dirpath, dirnames, filenames) in os.walk(dirname):
f.extend(filenames)
break
if extension is not None:
# Filter on extension
... | 84fd78dad7e624754ba4b39e1cf09f9a09748fca | 18,082 |
def make_invalid_varname_comment(varname: str):
"""Make a comment about a Stata varname being invalid."""
return f'* Invalid STATA varname: {varname}' | e40dc6a8d15d81a9af3e25825f0ff424379c73ca | 18,083 |
def GetFoldTypeFromAnnotation(line):#{{{
"""Get foldType from the annotation line of the topomsa file
In the *.topomsa files, the header line has now been tagged with
fold-type (5B,7B, 6R - 5 helical broken fold-type, 7 helical broken
fold-type , 6 helical broken fold-type) in column 3.
... | 1c0b6f90b7d22cb78b8828cbd9c6d74867d430ae | 18,084 |
def avatar_to_dict(avatar):
"""Creates a Python dict for an Avatar database entity.
This is an admin-only function that exposes more database information than
the method on Avatar.
"""
return dict(
id=avatar.id,
flake=avatar.flake,
uri=avatar.uri,
user=avatar.user.to... | 3ccb7da50aee0ccd847a8f38f60c02c7b7f2a820 | 18,085 |
def get_skip_comments(events, skip_users=None):
"""
Determine comment ids that should be ignored, either because of
deletion or because the user should be skipped.
Args:
events: a list of (event_type str, event_body dict, timestamp).
Returns:
comment_ids: a set of comment ids th... | 30663624714104bc7b9aa0fd4da45f537b06420f | 18,086 |
def encode_jump(input_string):
"""Encode input string according to algorithm specifications"""
jump_map = {
"0": "5",
"1": "9",
"2": "8",
"3": "7",
"4": "6",
"5": "0",
"6": "4",
"7": "3",
"8": "2",
"9": "1",
}
output_string ... | b316ffab520ce2cdbc97e9711b897e85081a827e | 18,087 |
def numberOfSteps (self, num):
"""
:type num: int
:rtype: int
len is slow
64% faster
85% less mem
"""
binary = bin(num)[2:]
return binary.count('1') * 2 + binary.count('0') - 1 | 1eba817694af7d798a8717a5ecae5a80abf942b1 | 18,088 |
def sluggify(text):
"""
Create a file system friendly string from passed text by stripping special characters.
Use this function to make file names from arbitrary text, like titles
:param text:
:return:
"""
if not text:
return ''
data = ''.join([c for c in text if c.isalpha() or... | a597f1625ee215314a77832b5f0fce2b7884c30b | 18,089 |
def UnZeroMatrix(matrix):
"""
replaces all instances of 0.0000 in the
matrix with the lowest observed non-zero value
assumes first row and first column of matrix are
descriptors
"""
minNonZero = min([float(m) for m in matrix[1][1:]])
for line in matrix[2:]:
for el in line[1:]:
if float(el) !=... | 8ede8d57e009aa8248f73d70fe48d4c4ea80baa8 | 18,090 |
def _get_input(query_str):
"""Get float-valued input."""
while True:
try:
temp = float(input(query_str))
return temp
except:
print("Unrecognized input!")
pass | 22b8ac5e24e484dbf8842f297866569281f32878 | 18,092 |
def test_policy(env, pie, max_steps, verbose=0, render=0):
""" test policy for one episode or end of mas_steps; returns (steps, return) """
cs, act, reward, done, steps = env.reset(), 0, 0, False, 0
total_reward = 0
if verbose>0:
print('[RESET]')
if render==2:
env.render()
while... | 28017b78e0bbfc1c29c30a6dd6e7d6cecdda3478 | 18,093 |
def prepare_df(df):
"""
This function converts the df header into string format
for the gui to be able to plot
Args:
df --> pandas dataframe: df needs to be cleaned
Return:
df --> pandas dataframe: cleaned df
"""
columns = list(df.columns.values)
for num, item in enumer... | b1028f0a791dc4e10d3cfdf5f43bf259a8e34a9b | 18,095 |
def sign(a):
"""Gets the sign of a scalar input."""
if a >= 0:
return 1
else:
return 0 | 365d05998ebd5146881a2e3c1a4003d3ed02f681 | 18,096 |
def resize_based_on_aspect_ratio(aspect_ratio, base_width, max_width=400):
"""アスペクト比を元にリサイズ後のwidth, heightを求める"""
if base_width < max_width:
return None
base = max_width / aspect_ratio[0]
new_w = int(base * aspect_ratio[0])
new_h = int(base * aspect_ratio[1])
return (new_w, new_h) | 3ae395e5e9bab27b00ed8ed57490dd1d342e61a5 | 18,097 |
import re
def isValidURL(str: str):
"""
Input: String
Output: Boolean
Checks if the URL are valid or not
"""
regex = ("((http|https)://)(www.)?" +
"[a-zA-Z0-9@:%._\\+~#?&//=]" +
"{2,256}\\.[a-z]" +
"{2,6}\\b([-a-zA-Z0-9@:%" +
"._\\+~#?&//=]*)... | 9b30a556f5a38fdde8e03a6084369449b2da9ea1 | 18,098 |
def create_expected_output(parameters, actual_data):
"""
This function creates the dict using given parameter and actual data
:param parameters:
:param actual_data:
:return: expected data
:type: dict
"""
expected_output = {}
for key in parameters:
for value in actual_data:
... | 356b8e50e9ee48bead784ff3cad3778b9076c3c5 | 18,099 |
def smartScale(gdk, src, resolution):
"""
**SUMMARY**
Resizes an image preserving its aspect ratio. Copied from adaptive scale.
Is used to resize image for the display
**PARAMETERS**
* *gdk* - A gdk module object
* *src* - The source pixbuf ( gtk.gdk.pixbuf )
* *... | e59c943334a8f16a5b1787f97c07b3ec7aaf7d32 | 18,100 |
def data_split(dataset, split_at=0.8, random_state=42):
"""split data into partitions randomly
"""
train = dataset.sample(frac=split_at, random_state=random_state)
test = dataset.drop(train.index)
return train, test | 153de855dcb2fa74b7d330a057d62850d9250e6c | 18,101 |
def where2(value1, value2, ls, interval):
"""Find where the value1 and value2 are located in ls, where the interval between neighboring elements are given.
This function may be faster than where, but might be slower in case that the interval is irregular.
This function returns the slice of ls betw... | 37fd1248f74e0ffc3a6194f0755f1075d745093f | 18,102 |
import os
def coco_as_image_name(dataset, label):
"""Convert a COCO detection label to the image name.
Args:
label (list of dict): an image label in the COCO detection format.
Returns:
str: image name.
"""
if not label:
return None
image_id = label[0]['image_id']
... | c56dbb23cec5e7293111e52e6e1dfac3bd6657d2 | 18,103 |
import sqlite3
def create_connection(database_name):
"""Create database connection"""
return sqlite3.connect(database_name) | 754d569fef76bc9b498efab176f33ed35fc60f6c | 18,104 |
def decorate_table(table_text, convert_fun, d_cols=" & ", d_rows="\\\\\n"):
"""Transforms text of the table by applying converter function to each element of this table.
:param table_text: (str) text of the table.
:param convert_fun: (str => str) a function to be applied to each element of the table.
:... | 55788a8ffb853702b81b38dc446ca9951371f9c9 | 18,105 |
def _qualname(cls):
"""
Returns a fully qualified name of the class, to avoid name collisions.
"""
return u'.'.join([cls.__module__, cls.__name__]) | 530fb5a7e9231702850c4bc8be09e9ca7e9dd8f5 | 18,107 |
def normalize_index(header, method):
"""
Equivalent to:
self.votes_index = self.header.index(
''.join(votes(self.header)))
"""
return header.index(''.join(method(header))) | 76a099d0ed9913b1909082b26c60e2db25c97905 | 18,109 |
import sys
def type_hints_equal(hint1, hint2):
"""Returns true if type hints equal.
For example:
type_hints_equal(typing.List, list) => True
"""
assert hint1 is not None
assert hint2 is not None
if hint1 is hint2:
return True
h1 = getattr(hint1, '__origin__', hint1) or ... | 60c14b5563a73028ba5e7cb53db4e5b4184e98a5 | 18,110 |
def largeur_image(lst, largeur_bande):
"""
Calcul la largeur de l'image composee de bandes de largeur
largeur_bande, noires ou blanches definies par lst
"""
return len(lst)*largeur_bande | ef42c5cb0a9d4f17c87e823bd4d6373d21095fae | 18,111 |
def gcd(a, b):
"""最大公约数辗转相除法"""
if a < b:
a, b = b, a
x = a % b
while x != 0:
x = a % b
a = b
b = x
return a | 084f4972f1e6490ab0fb60df48641bf622b36288 | 18,114 |
def _check_name_should_break(name):
"""
Checks whether the passed `name` is type `str`.
Used inside of ``check_name`` to check whether the given variable is usable, so we should stop checking
other alternative cases.
Parameters
----------
name : `Any`
Returns
-------
... | 4e6981fa840b89bf69a1a0e6c6401b1e2387e17d | 18,115 |
def close_mail_session(server):
"""
Mail session termination
"""
# Terminate the SMTP session and close the connection
server.quit()
return True | 421bf144f2e499aea60dddf3274bd0b8e910d155 | 18,116 |
def my_permutation(nums: list) -> list:
"""backtrack
Args:
nums (list)
Returns:
permutation_list
"""
res = []
visited_list = [0] * len(nums)
def dfs(path_list):
if len(path_list) == len(nums):
res.append(path_list)
else:
for i in ra... | cf080febe9474dc53d1937b9ba92c12515fb5be9 | 18,118 |
def normalize_ns(namespaces: str) -> str:
"""
Normalizes url names by collapsing multiple `:` characters.
:param namespaces: The namespace string to normalize
:return: The normalized version of the url path name
"""
return ':'.join([nmsp for nmsp in namespaces.split(':') if nmsp]) | 3be2e6cf1615d9610ec6695966c9c32f4b531ea3 | 18,119 |
def get_param_dict(df, column_name, cast_as_type):
"""
:param df: the project-params dataframe
:param column_name: string, column name of the parameter to look for
:param cast_as_type: the type for the parameter
:return: dictionary, {project: param_value}
Create a dictionary for the parameter t... | b2b0dd2626e9cceb1dec18e14467178e42f1fd06 | 18,121 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.