MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

↓ 1 callersFunctionbuild_tree
Build and return a sample binary tree. Returns: TreeNode: The root of the binary tree. Examples: >>> root = build_tree(
data_structures/binary_tree/flatten_binarytree_to_linkedlist.py:29
↓ 1 callersFunctionbutterfly_pattern
Creates a butterfly pattern of size n and returns it as a string. >>> print(butterfly_pattern(3)) * * ** ** ***** ** **
graphics/butterfly_pattern.py:1
↓ 1 callersFunctionbwt_transform
:param s: The string that will be used at bwt algorithm :return: the string composed of the last char of each row of the ordered rotation
data_compression/burrows_wheeler.py:54
↓ 1 callersMethodcal_gradient
(self)
neural_network/back_propagation_neural_network.py:60
↓ 1 callersMethodcal_loss
(self, ydata, ydata_)
neural_network/back_propagation_neural_network.py:160
↓ 1 callersFunctioncalc_derivative
Approximate the derivative of a function f(x) at a point x using the finite difference method >>> import math >>> tolerance = 1e-5
maths/numerical_analysis/newton_raphson.py:18
↓ 1 callersFunctioncalc_profit
Function description is as follows- :param profit: Take a list of profits :param weight: Take a list of weight if bags corresponding to t
knapsack/greedy_knapsack.py:20
↓ 1 callersFunctioncalculate_average_times
This function calculates the average of the waiting & turnaround times Prints: Average Waiting time & Average Turn Around Time >>> calcul
scheduling/shortest_job_first.py:95
↓ 1 callersFunctioncalculate_average_turnaround_time
This function calculates the average of the turnaround times Return: The average of the turnaround times. >>> calculate_average_turna
scheduling/first_come_first_served.py:47
↓ 1 callersFunctioncalculate_average_waiting_time
This function calculates the average of the waiting times Return: The average of the waiting times. >>> calculate_average_waiting_tim
scheduling/first_come_first_served.py:61
↓ 1 callersMethodcalculate_completion_time
This method calculates completion time of processes >>> P1 = Process("P1", 0, 53) >>> P2 = Process("P2", 0, 17) >>> P
scheduling/multi_level_feedback_queue.py:94
↓ 1 callersFunctioncalculate_current_element
>>> triangle = [[1], [1, 1]] >>> current_row = [1, -1, 1] >>> calculate_current_element(triangle, current_row, 2, 1) >>> current_row
matrix/pascal_triangle.py:93
↓ 1 callersFunctioncalculate_each_score
>>> calculate_each_score([[20, 23, 22], [60, 90, 50], [2012, 2015, 2011]], ... [0, 0, 1]) [[1.0, 0.0, 0.333333333333
other/scoring_algorithm.py:41
↓ 1 callersFunctioncalculate_fft
Calculate the Fast Fourier Transform (FFT) of windowed audio data. Args: audio_windowed: The windowed audio signal. ftt_size
machine_learning/mfcc.py:218
↓ 1 callersMethodcalculate_heuristic
The heuristic here is the Manhattan Distance Could elaborate to offer more than one choice
graphs/greedy_best_first.py:74
↓ 1 callersMethodcalculate_heuristic
Heuristic for the A*
graphs/bidirectional_a_star.py:63
↓ 1 callersFunctioncalculate_mean
Calculate given class mean :param instance_count: Number of instances in class :param items: items that related to specific class(data gr
machine_learning/linear_discriminant_analysis.py:94
↓ 1 callersFunctioncalculate_pi
https://en.wikipedia.org/wiki/Leibniz_formula_for_%CF%80 Leibniz Formula for Pi The Leibniz formula is the special case arctan(1) = pi /
maths/pi_generator.py:1
↓ 1 callersFunctioncalculate_prime_numbers
Returns prime numbers below max_number >>> calculate_prime_numbers(10) [2, 3, 5, 7]
project_euler/problem_800/sol1.py:16
↓ 1 callersFunctioncalculate_probabilities
Calculate the probability that a given instance will belong to which class :param instance_count: number of instances in class :param tot
machine_learning/linear_discriminant_analysis.py:110
↓ 1 callersMethodcalculate_sequence_of_finish_queue
This method returns the sequence of finished processes >>> P1 = Process("P1", 0, 53) >>> P2 = Process("P2", 0, 17) >>
scheduling/multi_level_feedback_queue.py:43
↓ 1 callersFunctioncalculate_signal_power
Calculate the power of the audio signal from its FFT. Args: audio_fft: The FFT of the audio signal. Returns: The power
machine_learning/mfcc.py:254
↓ 1 callersFunctioncalculate_span
Calculate the span values for a given list of stock prices. Args: price: List of stock prices. Returns: List of span valu
data_structures/stacks/stock_span_problem.py:11
↓ 1 callersFunctioncalculate_turn_around_time
Calculate the turn around time of each processes Return: The turn around time time for each process. >>> calculate_turn_around_time(["A"
scheduling/highest_response_ratio_next.py:13
↓ 1 callersFunctioncalculate_turn_around_times
>>> calculate_turn_around_times([1, 2, 3, 4], [0, 1, 3]) [1, 3, 6] >>> calculate_turn_around_times([10, 3, 7], [10, 6, 11]) [20,
scheduling/round_robin.py:44
↓ 1 callersMethodcalculate_turnaround_time
This method calculates turnaround time of processes >>> P1 = Process("P1", 0, 53) >>> P2 = Process("P2", 0, 17) >>> P
scheduling/multi_level_feedback_queue.py:77
↓ 1 callersFunctioncalculate_turnaround_times
This function calculates the turnaround time of some processes. Return: The time difference between the completion time and the
scheduling/first_come_first_served.py:26
↓ 1 callersFunctioncalculate_turnaroundtime
Calculate the turnaround time of each process. Return: The turnaround time for each process. >>> calculate_turnaroundtime([0,1,2], 3, [0
scheduling/non_preemptive_shortest_job_first.py:70
↓ 1 callersFunctioncalculate_turnaroundtime
Calculate the turn around time of each Processes Return: list of turn around times. >>> calculate_turnaroundtime([3,3,5,1], 4, [0,3,5,0])
scheduling/shortest_job_first.py:76
↓ 1 callersFunctioncalculate_variance
Calculate the variance :param items: a list containing all items(gaussian distribution of all classes) :param means: a list containing re
machine_learning/linear_discriminant_analysis.py:127
↓ 1 callersFunctioncalculate_waiting_time
Calculate the waiting time of each processes. Return: The waiting time for each process. >>> calculate_waiting_time(["A", "B", "C"], [2,
scheduling/highest_response_ratio_next.py:76
↓ 1 callersMethodcalculate_waiting_time
This method calculates waiting time of processes >>> P1 = Process("P1", 0, 53) >>> P2 = Process("P2", 0, 17) >>> P3 =
scheduling/multi_level_feedback_queue.py:60
↓ 1 callersFunctioncalculate_waiting_times
Calculate the waiting times of a list of processes that have a specified duration. Return: The waiting time for each process. >>> ca
scheduling/round_robin.py:12
↓ 1 callersFunctioncalculate_waiting_times
This function calculates the waiting time of some processes that have a specified duration time. Return: The waiting time for each pr
scheduling/first_come_first_served.py:8
↓ 1 callersFunctioncalculate_waitingtime
Calculate the waiting time of each processes Return: The waiting time for each process. >>> calculate_waitingtime([0,1,2], [10, 5, 8], 3
scheduling/non_preemptive_shortest_job_first.py:13
↓ 1 callersFunctioncalculate_waitingtime
Calculate the waiting time of each processes Return: List of waiting times. >>> calculate_waitingtime([1,2,3,4],[3,3,5,1],4) [0, 3, 5
scheduling/shortest_job_first.py:12
↓ 1 callersFunctioncan_string_be_rearranged_as_palindrome
A Palindrome is a String that reads the same forward as it does backwards. Examples of Palindromes mom, dad, malayalam >>> can_string_be_
strings/can_string_be_rearranged_as_palindrome.py:29
↓ 1 callersFunctioncanny
(image, threshold_low=15, threshold_high=30, weak=128, strong=255)
digital_image_processing/edge_detection/canny.py:119
↓ 1 callersFunctioncatalan_numbers
Return a list of the Catalan number sequence from 0 through `upper_limit`. >>> catalan_numbers(5) [1, 1, 2, 5, 14, 42] >>> catalan_n
dynamic_programming/catalan_numbers.py:30
↓ 1 callersFunctionceil_index
(v, left, right, key)
dynamic_programming/longest_increasing_subsequence_o_nlogn.py:10
↓ 1 callersFunctioncentroid_pairwise_dist
(x, centroids)
machine_learning/k_means_clust.py:79
↓ 1 callersFunctionchain_length
Calculate the length of the chain of non-repeating terms starting with n. Previous is a set containing the previous member of the chain.
project_euler/problem_074/sol1.py:73
↓ 1 callersFunctionchange_brightness
Change the brightness of a PIL Image to a given level.
digital_image_processing/change_brightness.py:4
↓ 1 callersMethodchange_component
changes the x-y component of this matrix
linear_algebra/src/lib.py:374
↓ 1 callersFunctionchange_contrast
Function to change contrast
digital_image_processing/change_contrast.py:14
↓ 1 callersMethodchange_stage
Exits first phase of the two-stage method by deleting artificial rows and columns, or completes the algorithm if exiting the standard
linear_programming/simplex.py:173
↓ 1 callersFunctioncheck
>>> check(['0.00.01.5']) ['0.00.01.5']
boolean_algebra/quine_mc_cluskey.py:28
↓ 1 callersFunctioncheck
Takes a number and checks if it is pandigital both from start and end >>> check(123456789987654321) True >>> check(120000987654321
project_euler/problem_104/sol1.py:21
↓ 1 callersFunctioncheck1
Takes a number and checks if it is pandigital from END >>> check1(123456789987654321) True >>> check1(120000987654321) True
project_euler/problem_104/sol1.py:70
↓ 1 callersFunctioncheck_anagrams
Two strings are anagrams if they are made up of the same letters but are arranged differently (ignoring the case). >>> check_anagrams(
strings/check_anagrams.py:8
↓ 1 callersFunctioncheck_bouncy
Returns True if number is bouncy, False otherwise >>> check_bouncy(6789) False >>> check_bouncy(-12345) False >>> check
project_euler/problem_112/sol1.py:20
↓ 1 callersFunctioncheck_circuit_or_path
(graph, max_node)
graphs/eulerian_path_and_circuit_for_undirected_graph.py:19
↓ 1 callersMethodcheck_color_properties
Check the coloring of the tree, and return True iff the tree is colored in a way which matches these five properties: (wording stole
data_structures/binary_tree/red_black_tree.py:278
↓ 1 callersMethodcheck_coloring
A helper function to recursively check Property 4 of a Red-Black Tree. See check_color_properties for more info.
data_structures/binary_tree/red_black_tree.py:311
↓ 1 callersMethodcheck_determinant
>>> hill_cipher = HillCipher(np.array([[2, 5], [1, 6]])) >>> hill_cipher.check_determinant()
ciphers/hill_cipher.py:86
↓ 1 callersFunctioncheck_direction
Return the direction toward to the line from via to target from starting :param starting: The starting point via: The via point
other/graham_scan.py:51
↓ 1 callersMethodcheck_is_full
(self)
data_structures/queues/circular_queue_linked_list.py:146
↓ 1 callersFunctioncheck_matrix
(matrix: list[list[int]])
matrix/spiral_print.py:10
↓ 1 callersFunctioncheck_negative_cycle
( graph: list[dict[str, int]], distance: list[float], edge_count: int )
graphs/bellman_ford.py:10
↓ 1 callersFunctioncheck_partition_perfect
Check if t = f(positive_integer) = log2(sqrt(4*positive_integer+1)/2 + 1/2) is a real number. >>> check_partition_perfect(2) True
project_euler/problem_207/sol1.py:44
↓ 1 callersFunctioncheck_valid_key
(key: str)
ciphers/simple_substitution_cipher.py:24
↓ 1 callersFunctioncheck_validity
Function checks if the input provided is valid or not. Function takes number_of_bands and colors as input and returns True if it is valid
electronics/resistor_color_code.py:260
↓ 1 callersFunctioncipher_text
>>> cipher_text("THE GERMAN ATTACK","SECRETSECRETSECRE") 'BDC PAYUWL JPAIYI'
ciphers/beaufort_cipher.py:33
↓ 1 callersFunctioncircle_sort
A pure Python implementation of circle sort algorithm :param collection: a mutable collection of comparable items in any order :return: the s
sorts/circle_sort.py:12
↓ 1 callersFunctioncircle_sort_util
>>> arr = [5,4,3,2,1] >>> circle_sort_util(lst, 0, 2) True >>> arr [3, 4, 5, 2, 1]
sorts/circle_sort.py:33
↓ 1 callersFunctioncity_select
Choose the next city for ants >>> city_select(pheromone=[[1.0, 1.0], [1.0, 1.0]], current_city={0: [0, 0]}, ... unvisited_cit
graphs/ant_colony_optimization_algorithms.py:168
↓ 1 callersMethodclassify
Classify a given point using the kNN algorithm >>> train_X = np.array( ... [[0, 0], [1, 0], [0, 1], [0.5, 0.5], [3, 3], [
machine_learning/k_nearest_neighbours.py:47
↓ 1 callersMethodcleanup
(self)
sorts/external_sort.py:43
↓ 1 callersFunctionclosest_pair_of_points
>>> closest_pair_of_points([(2, 3), (12, 30)], len([(2, 3), (12, 30)])) 28.792360097775937
divide_and_conquer/closest_pair_of_points.py:125
↓ 1 callersFunctionclosest_pair_of_points_sqr
divide and conquer approach Parameters : points, points_count (list(tuple(int, int)), int) Returns : (float): distance btw closest
divide_and_conquer/closest_pair_of_points.py:82
↓ 1 callersFunctionclosing_filter
Opening filter, defined as the sequence of dilation and then erosion filter on the same image. Examples: >>> img = np.array([[1,
computer_vision/haralick_descriptors.py:178
↓ 1 callersFunctioncocktail_shaker_sort
Sorts a list using the Cocktail Shaker Sort algorithm. :param arr: List of elements to be sorted. :return: Sorted list. >>> cocktai
sorts/cocktail_shaker_sort.py:8
↓ 1 callersFunctioncollatz_sequence
Generate the Collatz sequence starting at n. >>> tuple(collatz_sequence(2.1)) Traceback (most recent call last): ... Exceptio
maths/collatz_sequence.py:20
↓ 1 callersFunctioncollatz_sequence_length
Returns the Collatz sequence length for n.
project_euler/problem_014/sol2.py:34
↓ 1 callersFunctioncollect_dataset
Collects the dataset (Iris dataset) and returns feature matrix and target values. :return: Tuple containing feature matrix (X) and target la
machine_learning/principle_component_analysis.py:20
↓ 1 callersFunctioncollect_dataset
Collect dataset of CSGO The dataset contains ADR vs Rating of a Player :return : dataset obtained from the link, as matrix
machine_learning/linear_regression.py:23
↓ 1 callersFunctioncollect_dataset
Load the Iris dataset and return features and labels. Returns: tuple[ndarray, ndarray]: Feature matrix and target labels. >>> f
machine_learning/t_stochastic_neighbour_embedding.py:15
↓ 1 callersMethodcolumns
(self)
matrix/matrix_class.py:131
↓ 1 callersFunctioncomb_sort
Pure implementation of comb sort algorithm in Python :param data: mutable collection with comparable items :return: the same collection in asc
sorts/comb_sort.py:22
↓ 1 callersFunctioncombination_lists
Generates all possible combinations of k numbers out of 1 ... n using itertools. >>> combination_lists(n=4, k=2) [[1, 2], [1, 3], [1, 4]
backtracking/all_combinations.py:13
↓ 1 callersFunctioncombination_sum
>>> combination_sum([2, 3, 5], 8) [[2, 2, 2, 2], [2, 3, 3], [3, 5]] >>> combination_sum([2, 3, 6, 7], 7) [[2, 2, 3], [7]] >>> com
backtracking/combination_sum.py:41
↓ 1 callersFunctioncombination_sum_iv
Function checks the all possible combinations, and returns the count of possible combination in exponential Time Complexity. >>> combina
dynamic_programming/combination_sum_iv.py:26
↓ 1 callersFunctioncomp_and_swap
Compare the value at given index1 and index2 of the array and swap them as per the given direction. The parameter direction indicates the sor
sorts/bitonic_sort.py:10
↓ 1 callersFunctioncompare_string
>>> compare_string('0010','0110') '0_10' >>> compare_string('0110','1101') False
boolean_algebra/quine_mc_cluskey.py:7
↓ 1 callersMethodcomplement
Calculate the complement (negation) of this fuzzy set. Returns: FuzzySet: A new fuzzy set representing the complement.
fuzzy_logic/fuzzy_operations.py:77
↓ 1 callersFunctioncomplete_graph
Generate a complete graph with vertices_number vertices. @input: vertices_number (number of vertices), directed (False if the gra
graphs/random_graph_generator.py:50
↓ 1 callersMethodcomponent
returns the specified (x,y) component
linear_algebra/src/lib.py:365
↓ 1 callersFunctioncompound_interest
>>> compound_interest(10000.0, 0.05, 3) 1576.2500000000014 >>> compound_interest(10000.0, 0.05, 1) 500.00000000000045 >>> compoun
financial/interest.py:42
↓ 1 callersFunctioncompress
Reads source file, decompresses it and writes the result in destination file
data_compression/lempel_ziv_decompress.py:100
↓ 1 callersMethodcompress
Compress a single value. Args: original: The value to compress. Returns: The compressed integer, or -1 if n
data_compression/coordinate_compression.py:82
↓ 1 callersMethodcompress_coordinates
Compress the coordinates in the input list. >>> arr = [100, 10, 52, 83] >>> cc = CoordinateCompressor(arr) >>> cc.co
data_compression/coordinate_compression.py:60
↓ 1 callersFunctioncompress_data
Compresses given data_bits using Lempel-Ziv-Welch compression algorithm and returns the result as a string
data_compression/lempel_ziv.py:44
↓ 1 callersFunctioncompute
same as next_term(a_i, k, i, n) but computes terms without memoizing results.
project_euler/problem_551/sol1.py:109
↓ 1 callersFunctioncompute_ap
(graph)
graphs/articulation_points.py:2
↓ 1 callersFunctioncompute_geometric_mean
Return the geometric mean of the argument numbers. >>> compute_geometric_mean(2,8) 4.0 >>> compute_geometric_mean('a', 4) Traceba
maths/geometric_mean.py:8
↓ 1 callersFunctioncompute_heterogeneity
(data, k, centroids, cluster_assignment)
machine_learning/k_means_clust.py:108
↓ 1 callersFunctioncompute_low_dim_affinities
Compute low-dimensional affinities (Q matrix) using a Student-t distribution. Args: embedding_matrix: Low-dimensional embedding of s
machine_learning/t_stochastic_neighbour_embedding.py:61
↓ 1 callersFunctioncompute_nums
Returns a list of first n odd composite numbers which do not follow the conjecture. >>> compute_nums(1) [5777] >>> compute_n
project_euler/problem_046/sol1.py:67
↓ 1 callersFunctioncompute_pairwise_affinities
Compute high-dimensional affinities (P matrix) using a Gaussian kernel. Args: data_matrix: Input data of shape (n_samples, n_feature
machine_learning/t_stochastic_neighbour_embedding.py:32
↓ 1 callersFunctioncompute_transform_tables
Finds the most cost efficient sequence for converting one string into another. >>> costs, operations = compute_transform_tables("cat", "
strings/min_cost_string_conversion.py:12
← previousnext →901–1,000 of 3,909, ranked by callers