mathematical.utils
Utilities for mathematical operations.
Classes:
|
Returns a range of floating-point numbers. |
Functions:
|
Concatenate multiple CSV files together and return a |
|
Returns the GCD (HCF) of |
|
Returns the GCD (HCF) of a list of numbers using Euclid’s Algorithm. |
|
Returns the GCD for an array of numbers using Euclid’s Algorithm. |
|
Returns the GCD (HCF) of |
|
Returns the GCD (HCF) of a list of numbers using Euclid’s Algorithm. |
|
Integer divsions which rounds toward zero. |
|
Checks whether a float is an integer value. |
|
Returns the LCM of a list of numbers using Euclid’s Algorithm. |
Returns the natural logarithm of |
|
|
Returns the magnitude of the given value. |
|
Returns the modular inverse of |
|
Returns the mean of the given sequence, ignoring |
|
Returns the relative standard deviation of the given sequence, ignoring |
|
Returns the standard deviation of the given sequence, ignoring |
|
Remove zero values from the given list. |
Checks whether a value can be converted to an |
|
|
Retuns the Roman numeral represtation of the given value. |
|
Round a value to the specified number format, e.g. |
|
Remove booleans from a list. |
Remove |
|
|
Remove |
|
Remove strings from a list. |
-
class
FRange
(stop: float)[source] -
class
FRange
(start: float, stop: float, step: float = ...) -
Returns a range of floating-point numbers.
The arguments to the range constructor may be integers or floats.
- Parameters
- Raises
ValueError – If step is zero, or if any value is larger than 1×10 14.
New in version 0.2.0.
Methods:
__contains__
(o)Returns whether
o
is in the range.__delattr__
(key)Implement
delattr(self, name)
.__eq__
(other)Return
self == other
.__getitem__
(item)Returns the value in the range at index
item
.__iter__
()Iterates over values in the range.
__len__
()Returns the number of values in the range.
__repr__
()Return a string representation of the
FRange
.Returns
reversed(self)
.__setattr__
(key, value)Implement
setattr(self, name)
.count
(value)Returns
1
if the value is within the range,0
otherwise.index
(value)Returns the index of
value
in the range.Attributes:
The value of the
start
parameter (or0.0
if the parameter was not supplied)The value of the
step
parameter (or1.0
if the parameter was not supplied)The value of the
stop
parameter-
__delattr__
(key)[source] Implement
delattr(self, name)
.
-
__getitem__
(item)[source] Returns the value in the range at index
item
.- Parameters
item
- Overloads
__getitem__
(i:int
) ->int
__getitem__
(s:slice
) ->FRange
-
__reversed__
()[source] Returns
reversed(self)
.
-
__setattr__
(key, value)[source] Implement
setattr(self, name)
.
-
index
(value)[source] Returns the index of
value
in the range.- Parameters
value (
float
)- Raises
ValueError – if the value is not in the range.
- Return type
-
concatenate_csv
(*files, outfile=None)[source] Concatenate multiple CSV files together and return a
pandas.DataFrame
representing the output.- Parameters
- Return type
- Returns
A
pandas.DataFrame
containing the concatenated CSV data.
New in version 0.3.0.
-
gcd_array
(array)[source] Returns the GCD for an array of numbers using Euclid’s Algorithm.
Based on https://www.geeksforgeeks.org/python-program-for-gcd-of-more-than-two-or-array-numbers/
- Parameters
array
- Return type
-
hcf
(a, b) Returns the GCD (HCF) of
a
andb
using Euclid’s Algorithm.
-
hcf2
(numbers) Returns the GCD (HCF) of a list of numbers using Euclid’s Algorithm.
-
intdiv
(p, q)[source] Integer divsions which rounds toward zero.
Examples >>> intdiv(3, 2) 1 >>> intdiv(-3, 2) -1 >>> -3 // 2 -2
- Return type
-
isint
(num)[source] Checks whether a float is an integer value.
Note
This function only works with floating-point numbers
-
magnitude
(x)[source] Returns the magnitude of the given value.
- Parameters
x (
float
) – Numerical value to find the magnitude of.
Changed in version 0.2.0: Now returns the absolute magnitude of negative numbers.
- Return type
-
mod_inverse
(a, m)[source] Returns the modular inverse of
a % m
, which is the numberx
such thata × x % m = 1
.
-
nanmean
(ls, dtype=<class 'float'>)[source] Returns the mean of the given sequence, ignoring
None
andnumpy.nan
values etc.Similar to numpy.nanmean except it handles
None
.
-
nanrsd
(ls, dtype=<class 'float'>)[source] Returns the relative standard deviation of the given sequence, ignoring
None
andnumpy.nan
values etc.
-
nanstd
(ls, dtype=<class 'float'>)[source] Returns the standard deviation of the given sequence, ignoring
None
andnumpy.nan
values etc.Similar to numpy.nanstd except it handles
None
.
-
roman
(num)[source] Retuns the Roman numeral represtation of the given value.
Examples:
>>> roman(4) 'IV' >>> roman(17) 'XVII'
- Return type
-
rounders
(val_to_round, round_format)[source] Round a value to the specified number format, e.g.
"0.000"
for three decimal places.