additions to math standard library
-
math2.lcm(a, b)[source]
least common multiple
-
math2.accsum(it)[source]
Yield accumulated sums of iterable: accsum(count(1)) -> 1,3,6,10,...
-
math2.cumsum(it)
Yield accumulated sums of iterable: accsum(count(1)) -> 1,3,6,10,...
-
math2.dot(a, b)[source]
dot product
-
math2.product(nums)[source]
Product of nums
-
math2.vecadd(a, b, fillvalue=0)[source]
addition of vectors of inequal lengths
-
math2.vecsub(a, b, fillvalue=0)[source]
substraction of vectors of inequal lengths
-
math2.vecmul(a, b)[source]
product of vectors of inequal lengths
-
math2.vecdiv(a, b)[source]
quotient of vectors of inequal lengths
-
math2.veccompare(a, b)[source]
compare values in 2 lists. returns triple number of paris where [a<b, a==b, a==c]
-
math2.mean(data)[source]
mean of data
-
math2.variance(data, avg=None)[source]
variance of data
-
math2.stats(l)[source]
returns min,max,sum,sum2,avg,var of a list
-
math2.fibonacci()[source]
Generate fibonnacci serie
-
math2.factorial(num)[source]
Return factorial value of num (num!)
-
math2.is_integer(x, epsilon=1e-06)[source]
Return True if the float x “seems” an integer
-
math2.int_or_float(x, epsilon=1e-06)[source]
-
math2.divisors(n)[source]
Return all divisors of n: divisors(12) -> 1,2,3,6,12
-
math2.proper_divisors(n)[source]
Return all divisors of n except n itself.
-
math2.is_prime(n)[source]
Return True if n is a prime number (1 is not considered prime).
-
math2.get_primes(start=2, memoized=False)[source]
Yield prime numbers from ‘start’
-
math2.digits_from_num_fast(num)[source]
Get digits from num in base 10 (fast implementation)
-
math2.digits_from_num(num, base=10)[source]
Get digits from num in base ‘base’
-
math2.str_base(num, base, numerals='0123456789abcdefghijklmnopqrstuvwxyz')[source]
string representation of an ordinal in given base
-
math2.num_from_digits(digits, base=10)[source]
Get digits from num in base ‘base’
-
math2.is_palindromic(num, base=10)[source]
Check if ‘num’ in base ‘base’ is a palindrome, that’s it, if it can be
read equally from left to right and right to left.
-
math2.prime_factors(num, start=2)[source]
Return all prime factors (ordered) of num in a list
-
math2.factorize(num)[source]
Factorize a number returning occurrences of its prime factors
-
math2.greatest_common_divisor(a, b)[source]
Return greatest common divisor of a and b
-
math2.least_common_multiple(a, b)[source]
Return least common multiples of a and b
-
math2.triangle(x)[source]
The nth triangle number is defined as the sum of [1,n] values. http://en.wikipedia.org/wiki/Triangular_number
-
math2.is_triangle(x)[source]
-
math2.pentagonal(n)[source]
-
math2.is_pentagonal(n)[source]
-
math2.hexagonal(n)[source]
-
math2.get_cardinal_name(num)[source]
Get cardinal name for number (0 to 1 million)
-
math2.is_perfect(num)[source]
Return -1 if num is deficient, 0 if perfect, 1 if abundant
-
math2.number_of_digits(num, base=10)[source]
Return number of digits of num (expressed in base ‘base’)
-
math2.is_pandigital(digits, through=[1, 2, 3, 4, 5, 6, 7, 8, 9])[source]
Return True if digits form a pandigital number
-
math2.sets_dist(a, b)[source]
http://stackoverflow.com/questions/11316539/calculating-the-distance-between-two-unordered-sets
-
math2.sets_levenshtein(a, b)[source]
levenshtein distance on sets
@see: http://en.wikipedia.org/wiki/Levenshtein_distance
-
math2.levenshtein(seq1, seq2)[source]
return http://en.wikipedia.org/wiki/Levenshtein_distance distance between 2 iterables
http://en.wikibooks.org/wiki/Algorithm_Implementation/Strings/Levenshtein_distance#Python
-
math2.ncombinations(n, k)[source]
Combinations of k elements from a group of n
-
math2.combinations_with_replacement(iterable, r)[source]
combinations_with_replacement(‘ABC’, 2) –> AA AB AC BB BC CC