MCPcopy Create free account

hub / github.com/TheAlgorithms/Python / functions

Functions3,909 in github.com/TheAlgorithms/Python

Methodmerge
Merge two sets together using Union by rank heuristic Return True if successful Merge two disjoint sets >>> A = Disjo
data_structures/disjoint_set/alternate_disjoint_set.py:19
Functionmerge_sort
Returns a list of sorted array elements using merge sort. >>> from random import shuffle >>> array = [-2, 3, -10, 11, 99, 100000, 100, -200]
divide_and_conquer/mergesort.py:60
Functionmin_distance_up_bottom
>>> min_distance_up_bottom("intention", "execution") 5 >>> min_distance_up_bottom("intention", "") 9 >>> min_distance_up_bottom("
dynamic_programming/min_distance_up_bottom.py:14
Functionmin_path_sum
Find the path from top left to bottom right of array of numbers with the lowest possible sum and return the sum along this path. >>> min_
graphs/minimum_path_sum.py:1
Functionmin_steps_to_one
Minimum steps to 1 implemented using tabulation. >>> min_steps_to_one(10) 3 >>> min_steps_to_one(15) 4 >>> min_steps_to_one(6
dynamic_programming/minimum_steps_to_one.py:30
Functionmincost_tickets
>>> mincost_tickets([1, 4, 6, 7, 8, 20], [2, 7, 15]) 11 >>> mincost_tickets([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [2, 7, 15]) 17
dynamic_programming/minimum_tickets_cost.py:28
Functionminimum_cost_path
Find the minimum cost traced by all possible paths from top left to bottom right in a given matrix >>> minimum_cost_path([[2, 1], [3, 1]
dynamic_programming/minimum_cost_path.py:6
Functionminimum_squares_to_represent_a_number
Count the number of minimum squares to represent a number >>> minimum_squares_to_represent_a_number(25) 1 >>> minimum_squares_to_rep
dynamic_programming/minimum_squares_to_represent_a_number.py:5
Functionminimum_subarray_sum
Return the length of the shortest contiguous subarray in a list of numbers whose sum is at least target. Reference: https://stackoverflow.co
dynamic_programming/minimum_size_subarray_sum.py:4
Functionminimum_waiting_time
This function takes a list of query times and returns the minimum waiting time for all queries to be completed. Args: queries: A
greedy_methods/minimum_waiting_time.py:16
Functionminkowski_distance
This function calculates the Minkowski distance for a given order between two n-dimensional points represented as lists. For the case of orde
maths/minkowski_distance.py:1
Functionmish
Implements the Mish activation function. Parameters: vector (np.ndarray): The input array for Mish activation.
neural_network/activation_functions/mish.py:14
Functionmobius
Mobius function >>> mobius(24) 0 >>> mobius(-1) 1 >>> mobius('asd') Traceback (most recent call last): ..
maths/mobius_function.py:12
Functionmock_response
(*args, **kwargs)
web_programming/test_fetch_github_info.py:17
Functionmode
This function returns the mode(Mode as in the measures of central tendency) of the input data. The input list may contain any Datastructur
maths/average_mode.py:4
Functionmodular_division
Modular Division : An efficient algorithm for dividing b by a modulo n. GCD ( Greatest Common Divisor ) or HCF ( Highest Common Factor )
maths/modular_division.py:4
Functionmodular_division2
This function used the above inversion of a to find x = (b*a^(-1))mod n >>> modular_division2(4,8,5) 2 >>> modular_division2(3,8,5)
maths/modular_division.py:63
Functionmolarity_to_normality
Convert molarity to normality. Volume is taken in litres. Wikipedia reference: https://en.wikipedia.org/wiki/Equivalent_concentratio
conversions/molecular_chemistry.py:10
Functionmoles_of_gas_system
>>> moles_of_gas_system(100, 5, 10) 0.06013618199229246 >>> moles_of_gas_system(110, 5009, 1000) 5476.766101807144 >>> moles_of_g
physics/ideal_gas_law.py:73
Functionmoles_to_pressure
Convert moles to pressure. Ideal gas laws are used. Temperature is taken in kelvin. Volume is taken in litres. Pressure h
conversions/molecular_chemistry.py:26
Functionmoles_to_volume
Convert moles to volume. Ideal gas laws are used. Temperature is taken in kelvin. Volume is taken in litres. Pressure has
conversions/molecular_chemistry.py:46
Methodmove_ant
Performs three tasks: 1. The ant turns either clockwise or anti-clockwise according to the colour of the square that
cellular_automata/langtons_ant.py:37
Functionmps_speed_of_molecule
Takes the temperature (in K) and molar mass (in kg/mol) of a gas and returns the most probable speed of a molecule in the gas (in m/s).
physics/speeds_of_gas_molecules.py:82
Methodmrvi
Modified Normalized Difference Vegetation Index RVI https://www.indexdatabase.de/db/i-single.php?id=275 :return: index
digital_image_processing/index_calculation.py:432
Functionmsd_radix_sort
Implementation of the MSD radix sort algorithm. Only works with positive integers :param list_of_ints: A list of integers :return: Re
sorts/msd_radix_sort.py:11
Functionmsd_radix_sort_inplace
Inplace implementation of the MSD radix sort algorithm. Sorts based on the binary representation of the integers. >>> lst = [1, 345, 23,
sorts/msd_radix_sort.py:78
Functionmse
Examples(rounded for precision): >>> actual = [1,2,3];predict = [1,4,3] >>> float(np.around(mse(predict,actual),decimals = 2)) 1.33
machine_learning/scoring_functions.py:40
Functionmultiplicative_persistence
Return the persistence of a given number. https://en.wikipedia.org/wiki/Persistence_of_a_number >>> multiplicative_persistence(217)
maths/persistence.py:1
Functionmux
Implement a 2-to-1 Multiplexer. :param input0: The first input value (0 or 1). :param input1: The second input value (0 or 1). :para
boolean_algebra/multiplexer.py:1
Functionn_input_and_gate
Calculate AND of a list of input values >>> n_input_and_gate([1, 0, 1, 1, 0]) 0 >>> n_input_and_gate([1, 1, 1, 1, 1]) 1
boolean_algebra/and_gate.py:35
Functionnand_gate
Calculate NAND of the input values >>> nand_gate(0, 0) 1 >>> nand_gate(0, 1) 1 >>> nand_gate(1, 0) 1 >>> nand
boolean_algebra/nand_gate.py:18
Functionnatural_sort
Sort the given list of strings in the way that humans expect. The normal Python sort algorithm sorts lexicographically, so you might not
sorts/natural_sort.py:6
Methodndre
(self)
digital_image_processing/index_calculation.py:528
Functionneville_interpolate
Interpolate and evaluate a polynomial using Neville's method. Arguments: x_points, y_points: Iterables of x and correspondin
maths/numerical_analysis/nevilles_method.py:12
Methodnext_batch
Return the next `batch_size` examples from this data set.
neural_network/input_data.py:200
Methodngrdi
Normalized Difference self.green/self.red Normalized self.green self.red difference index, Visible Atmospherically Resistant Indi
digital_image_processing/index_calculation.py:475
Functionnimply_gate
Calculate NIMPLY of the input values >>> nimply_gate(0, 0) 0 >>> nimply_gate(0, 1) 0 >>> nimply_gate(1, 0) 1 >>> nim
boolean_algebra/nimply_gate.py:20
Functionnor_gate
>>> nor_gate(0, 0) 1 >>> nor_gate(0, 1) 0 >>> nor_gate(1, 0) 0 >>> nor_gate(1, 1) 0 >>> nor_gate(0.0, 0.0) 1
boolean_algebra/nor_gate.py:19
Methodnorm_g
Norm G https://www.indexdatabase.de/db/i-single.php?id=50 :return: index
digital_image_processing/index_calculation.py:451
Methodnorm_nir
Norm self.nir https://www.indexdatabase.de/db/i-single.php?id=51 :return: index
digital_image_processing/index_calculation.py:459
Methodnorm_r
Norm R https://www.indexdatabase.de/db/i-single.php?id=52 :return: index
digital_image_processing/index_calculation.py:467
Functionnormalization
Return a normalized list of values. @params: data, a list of values to normalize @returns: a list of normalized values (rounded to ndigi
machine_learning/data_transformations.py:32
Functionnormalize_image
Normalizes image in Numpy 2D array format, between ranges 0-cap, as to fit uint8 type. Args: image: 2D numpy array representing
computer_vision/haralick_descriptors.py:25
Functionnot_gate
Calculate NOT of the input values >>> not_gate(0) 1 >>> not_gate(1) 0
boolean_algebra/not_gate.py:15
Methodnum_columns
(self)
matrix/matrix_class.py:139
Functionnum_digits
Find the number of digits in a number. >>> num_digits(12345) 5 >>> num_digits(123) 3 >>> num_digits(0) 1 >>> num_dig
maths/number_of_digits.py:5
Functionnum_digits_fast
Find the number of digits in a number. abs() is used as logarithm for negative numbers is not defined. >>> num_digits_fast(12345) 5
maths/number_of_digits.py:38
Functionnum_digits_faster
Find the number of digits in a number. abs() is used for negative numbers >>> num_digits_faster(12345) 5 >>> num_digits_faster(1
maths/number_of_digits.py:65
Methodnum_examples
(self)
neural_network/input_data.py:193
Methodnum_rows
(self)
matrix/matrix_class.py:135
Functionnumber_of_divisors
Calculate Number of Divisors of an Integer. >>> number_of_divisors(100) 9 >>> number_of_divisors(0) Traceback (most recent call la
maths/basic_maths.py:34
Methodnumber_of_followers
(self)
web_programming/instagram_crawler.py:86
Methodnumber_of_followings
(self)
web_programming/instagram_crawler.py:90
Methodnumber_of_posts
(self)
web_programming/instagram_crawler.py:94
Functionobject_distance
Doctests: >>> from math import isclose >>> isclose(object_distance(10,40), -13.333333333333332) True >>> from math import isclos
physics/lens_formulae.py:79
Functionobject_distance
>>> from math import isclose >>> isclose(object_distance(30, 20), -60.0) True >>> from math import isclose >>> isclose(object_dis
physics/mirror_formulae.py:84
Functionoct_to_decimal
Convert a octal value to its decimal equivalent >>> oct_to_decimal("") Traceback (most recent call last): ... ValueError: Em
conversions/octal_to_decimal.py:1
Functionoctal_to_binary
Convert an Octal number to Binary. >>> octal_to_binary("17") '001111' >>> octal_to_binary("7") '111' >>> octal_to_binary("Av
conversions/octal_to_binary.py:11
Functionodd_sieve
Returns the prime numbers < `num`. The prime numbers are calculated using an odd sieve implementation of the Sieve of Eratosthenes algorithm
maths/odd_sieve.py:5
Functionoe_process
( position, value, l_send, r_send, lr_cv, rr_cv, result_pipe, multiprocessing_
sorts/odd_even_transposition_parallel.py:32
Functionohms_law
Apply Ohm's Law, on any two given electrical values, which can be voltage, current, and resistance, and then in a Python dict return name/val
electronics/ohms_law.py:5
Functionopen_knight_tour
Find the solution for the knight tour problem for a board of size n. Raises ValueError if the tour cannot be performed for the given size.
backtracking/knight_tour.py:71
Functionoptimal_merge_pattern
Function to merge all the files with optimum cost Args: files [list]: A list of sizes of different files to be merged Returns:
greedy_methods/optimal_merge_pattern.py:23
Functionor_gate
Calculate OR of the input values >>> or_gate(0, 0) 0 >>> or_gate(0, 1) 1 >>> or_gate(1, 0) 1 >>> or_gate(1, 1
boolean_algebra/or_gate.py:17
Methodorder
(self)
matrix/matrix_class.py:143
Methodout_degree
(self, u)
graphs/directed_and_undirected_weighted_graph.py:110
Functionpairs_with_sum
Return the no. of pairs with sum "sum" >>> pairs_with_sum([1, 5, 7, 1], 6) 2 >>> pairs_with_sum([1, 1, 1, 1, 1, 1, 1, 1], 2) 28
data_structures/arrays/pairs_with_given_sum.py:13
Functionpalindromic_string
>>> palindromic_string('abbbaba') 'abbba' >>> palindromic_string('ababa') 'ababa' Manacher's algorithm which finds Longest
strings/manacher.py:1
Methodparent_index
returns the parent index based on the given child index >>> h = Heap() >>> h.build_max_heap([103, 9, 1, 7, 11, 15, 25, 201,
data_structures/heap/heap.py:55
Methodpath_sum
(self, node: Node | None, target: int | None = None)
data_structures/binary_tree/binary_tree_path_sum.py:92
Functionpay
hours_worked = The total hours worked pay_rate = Amount of money per hour hours = Number of hours that must be worked before you receive
financial/time_and_half_pay.py:6
Functionpeak
Return the peak value of `lst`. >>> peak([1, 2, 3, 4, 5, 4, 3, 2, 1]) 5 >>> peak([1, 10, 9, 8, 7, 6, 5, 4]) 10 >>> peak([1, 9
divide_and_conquer/peak.py:14
Methodpeek
return min element without deleting it
data_structures/heap/binomial_heap.py:247
Methodpeek
(self)
data_structures/heap/min_heap.py:102
Methodpeek
>>> stack = LinkedStack() >>> stack.push("Java") >>> stack.push("C") >>> stack.push("Python") >>> stack.
data_structures/stacks/stack_with_singly_linked_list.py:132
Functionperfect_cube
Check if a number is a perfect cube or not. >>> perfect_cube(27) True >>> perfect_cube(4) False
maths/perfect_cube.py:1
Functionperfect_cube_binary_search
Check if a number is a perfect cube or not using binary search. Time complexity : O(Log(n)) Space complexity: O(1) >>> perfect_cube_
maths/perfect_cube.py:14
Functionperfect_square
Check if a number is perfect square number or not :param num: the number to be checked :return: True if number is square number, otherwis
maths/perfect_square.py:4
Functionperfect_square_binary_search
Check if a number is perfect square using binary search. Time complexity : O(Log(n)) Space complexity: O(1) >>> perfect_square_binar
maths/perfect_square.py:24
Methodperimeter
>>> Ellipse(5, 10).perimeter 47.12388980384689
geometry/geometry.py:103
Methodperimeter
(self)
geometry/geometry.py:258
Methodperimeter
(self)
geometry/geometry.py:280
Functionperiod_of_pendulum
>>> period_of_pendulum(1.23) 2.2252155506257845 >>> period_of_pendulum(2.37) 3.0888278441908574 >>> period_of_pendulum(5.63)
physics/period_of_pendulum.py:30
Functionpermute_recursive
Return all permutations. >>> permute_recursive([1, 2, 3]) [[3, 2, 1], [2, 3, 1], [1, 3, 2], [3, 1, 2], [2, 1, 3], [1, 2, 3]]
data_structures/arrays/permutations.py:1
Functionperplexity_loss
Calculate the perplexity for the y_true and y_pred. Compute the Perplexity which useful in predicting language model accuracy in Natural
machine_learning/loss_functions.py:484
Functionpi_estimator
An implementation of the Monte Carlo method used to find pi. 1. Draw a 2x2 square centred at (0,0). 2. Inscribe a circle within the squar
maths/monte_carlo.py:11
Functionpi_estimator_using_area_under_curve
Area under curve y = sqrt(4 - x^2) where x lies in 0 to 2 is equal to pi
maths/monte_carlo.py:103
Functionplot_runtimes
()
divide_and_conquer/max_subarray.py:95
Methodpndvi
Pan NDVI https://www.indexdatabase.de/db/i-single.php?id=188 :return: index
digital_image_processing/index_calculation.py:279
Functionpolar_angle_key
Key function for sorting points by polar angle relative to min_point. Points are sorted counter-clockwise. When two points have the
geometry/graham_scan.py:158
Functionpolygonal_num
Returns the `num`th `sides`-gonal number. It is assumed that `num` >= 0 and `sides` >= 3 (see for reference https://en.wikipedia.org/wiki/Pol
maths/special_numbers/polygonal_numbers.py:1
Methodpop
>>> stack = LinkedStack() >>> stack.pop() Traceback (most recent call last): ... IndexError: pop fro
data_structures/stacks/stack_with_singly_linked_list.py:108
Methodposition
(self)
physics/n_body_simulation.py:52
Functionpostorder
postOrder (left, right, self)
data_structures/binary_tree/binary_search_tree.py:343
Functionpotential_energy
>>> potential_energy(10,10) 980.665 >>> potential_energy(0,5) 0.0 >>> potential_energy(8,0) 0.0 >>> potential_energy(10,5
physics/potential_energy.py:31
Functionpower_of_4
Return True if this number is power of 4 or False otherwise. >>> power_of_4(0) Traceback (most recent call last): ... ValueE
bit_manipulation/power_of_4.py:18
Methodpredict
Get the expected class of an observation Args: observation (Vector): observation Returns: int {1, -
machine_learning/support_vector_machines.py:170
Methodpredict
(self, datas_test)
neural_network/convolution_neural_network.py:313
Functionprefix_sum
>>> prefix_sum([1, 4, 6, 2, 61, 12], [(2, 5), (1, 5), (3, 4)]) [81, 85, 63] >>> prefix_sum([4, 2, 1, 6, 3], [(3, 4), (1, 3), (0, 2)])
dynamic_programming/range_sum_query.py:64
Functionpresent_value
>>> present_value(0.13, [10, 20.70, -293, 297]) 4.69 >>> present_value(0.07, [-109129.39, 30923.23, 15098.93, 29734,39]) -42739.63
financial/present_value.py:12
← previousnext →3,401–3,500 of 3,909, ranked by callers