Skip to main content

Implementation of deciml library. Used for mathematical operations.

Project description

deciml_maths

pip install deciml_mathematics

Note - 'ret' argument is the 'r' argument of "retrn" function in "terminate" library.

Note - If 'chk' argument is False,

  • Incorrect argument types (Below declaration snippets in README) result in error.
  • Using List instead of Tuple can result in error.

If 'chk' is True,

  • Decimal type can be replaced with float, int, or string.

Note - Detailed description of arguments is available in the docstring.

Use the "setpr" function to set the precision for a calculation ("getpr" to check the precision).

Increase the precision value by 2 more than the precision that you want for more accurate calculations

>>> from deciml_maths import setpr, getpr
>>> setpr(29)
>>> getpr()
29

Abbrevations

  • c: class
  • o: object
  • sm: staticmethod
  • cm: classmethod
  • f: function
  • s: setter
  • g: getter
Matrix

matx

(o) matx(li, chk=True, ret='a'): Object that stores matrix properties

  • li - tuple[ tuple[Decimal, ...] ] | tuple[Decimal, ...]
>>> from deciml_maths.matrix import matx
Imported deciml...
>>> from deciml.deciml import setpr
>>> setpr(3)
>>> matrix = matx([[1.924,2.25452,3.35157],[2.2585441,3.35844,4.25841],[3.58425,4.365258,5.694222],[4.6945485,5.5875155,6.557885]],True,'w')
'''
    [[1.924,2.25452,3.35157],[2.2585441,3.35844,4.25841],[3.58425,4.365258,5.694222],[4.6945485,5.5875155,6.557885]] - 2-D matrix
    True: Check argument types
    'w': Wait and exit if error
'''
>>> print(matrix)
matx(
_____|___[0]___|___[1]___|___[2]___|
 (0) | '1.924' | '2.255' | '3.352' | 
 (1) | '2.259' | '3.358' | '4.258' | 
 (2) | '3.584' | '4.365' | '5.694' | 
 (3) | '4.695' | '5.588' | '6.558' | 
)

i. (s) matx: Assign a new 2-D matrix

>>> matrix.matx = [1.5, 2.8257, 3.25541]
>>> matrix.pmatx
matx(
_____|__[0]__|___[1]___|___[2]___|
 (0) | '1.5' | '2.826' | '3.255' | 
)

ii. (g) matx -> tuple: Get the 2-D matrix as a tuple

>>> mat = matrix.matx
>>> mat
((Decimal('1.5'), Decimal('2.826'), Decimal('3.255')),)

iii. (g) rowlen -> int: Get the length of rows

>>> matrix.rowlen
3

iv. (g) collen -> int: Get the length of columns

>>> matrix.collen
1

v. (g) sqmatx -> bool: Get if square matrix

>>> matrix.sqmatx
False

vi. (g) pmatx: Print the matrix and return the matrix as a tuple

Note - Can be used to check for errors. :'/ Change the matx to pmatx

matrix.pmatx
matx(
_____|__[0]__|___[1]___|___[2]___|
 (0) | '1.5' | '2.826' | '3.255' | 
)

v. (f) dnant() -> Decimal: Get the determinant of matrix

>>> matrix = matx([[1,2,3,5],[2,4,4,5],[3,4,8,6],[7,5,6,7]])
>>> matrix.dnant()
Decimal('-155.000')

vi. (f) invsednant() -> Decimal: Get the determinant of the inverse matrix

>>> matrix.invsednant()
Decimal('-0.006452')

vii. (f) invse() -> matx: Get the inverse matrix of the matrix

>>> mat = matrix.invse()
>>> print(mat)
matx(
_____|____[0]_____|___[1]____|____[2]_____|____[3]_____|
 (0) | '-0.05161' | '-0.219' | '-0.04516' |    '0.232' | 
 (1) |   '-0.426' |  '0.690' |   '-0.123' | '-0.08387' | 
 (2) | '-0.09677' | '-0.161' |    '0.290' | '-0.06452' | 
 (3) |    '0.439' | '-0.135' |   '-0.116' |  '0.02581' | 
)

vii. (f) adjnt() -> matx: Get the adjoint matrix of the matrix

>>> mat = matrix.adjnt()
>>> print(mat)
matx(
_____|___[0]___|___[1]____|___[2]___|___[3]___|
 (0) |   '8.0' |   '34.0' |   '7.0' | '-36.0' | 
 (1) |  '66.0' | '-107.0' |  '19.0' |  '13.0' | 
 (2) |  '15.0' |   '25.0' | '-45.0' |  '10.0' | 
 (3) | '-68.0' |   '21.0' |  '18.0' |  '-4.0' | 
)

viii. (f) tpose() -> matx: Get the transpose matrix of the matrix

>>> mat = matrix.tpose()
>>> print(mat)
matx(
_____|__[0]__|__[1]__|__[2]__|__[3]__|
 (0) | '1.0' | '2.0' | '3.0' | '7.0' | 
 (1) | '2.0' | '4.0' | '4.0' | '5.0' | 
 (2) | '3.0' | '4.0' | '8.0' | '6.0' | 
 (3) | '5.0' | '5.0' | '6.0' | '7.0' | 
)

ix. (f) cofacm() -> matx: Get the matrix of cofactors for the matrix

>>> mat = matrix.cofacm()
>>> print(mat)
matx(
_____|___[0]___|___[1]____|___[2]___|___[3]___|
 (0) |   '8.0' |   '66.0' |  '15.0' | '-68.0' | 
 (1) |  '34.0' | '-107.0' |  '25.0' |  '21.0' | 
 (2) |   '7.0' |   '19.0' | '-45.0' |  '18.0' | 
 (3) | '-36.0' |   '13.0' |  '10.0' |  '-4.0' | 
)

x. (f) mele(i, j, chk=True, ret='a') -> Decimal: Get an element of the matrix

  • i - int
  • j - int
>>> ele = matrix.mele(0,0,True,'e')
'''
  0 - Row index
  0 - Column index
  True - Check arguments
  'e' - Exit if error
'''
>>> ele
Decimal('1.0')

xi. (f) mrow(i, chk=True, ret='a') -> tuple[Decimal, ...]: Get a row of the matrix

  • i - int
>>> row = matrix.mrow(0, True, 'c')
'''
  0 - Row index
  True - Check arguments
  'c' - Continue if error
'''
>>> row
(Decimal('1.0'), Decimal('2.0'), Decimal('3.0'), Decimal('5.0'))

xii. (f) mcol(j, chk=True, ret='a') -> tuple[Decimal, ...]: Get a column of the matrix

  • j - int
>>> col = matrix.mcol(0, True, 'a')
'''
  0 - Column index
  True - Check arguments
  'a' - Ask to exit if error
'''
>>> col
(Decimal('1.0'), Decimal('2.0'), Decimal('3.0'), Decimal('7.0'))

xiii. (f) gele(a, r=False, chk=True, ret='a') -> tuple[ tuple[Decimal, ...] ]: Get the rows or columns of the matrix

  • a - list[ int ]
  • r - bool
>>> cols = matrix.gele([0,2], False, False, 'e')
'''
  [0,2] - Column indexes
  False - Get columns
  False - Skip arguments check
  'e' - Exit if error
'''
>>> cols
((Decimal('1.0'), Decimal('2.0'), Decimal('3.0'), Decimal('7.0')), (Decimal('3.0'), Decimal('4.0'), Decimal('8.0'), Decimal('6.0')))

xiv. (f) matxl() -> list[ list[ Decimal ] ]: Get the matrix as a list of Decimal objects

>>> matrix.matxl()
[[Decimal('1.0'), Decimal('2.0'), Decimal('3.0'), Decimal('5.0')], [Decimal('2.0'), Decimal('4.0'), Decimal('4.0'), Decimal('5.0')], [Decimal('3.0'), Decimal('4.0'), Decimal('8.0'), Decimal('6.0')], [Decimal('7.0'), Decimal('5.0'), Decimal('6.0'), Decimal('7.0')]]

xv. (f) pop(i, r=True, chk=True, ret='a') -> tuple[Decimal, ...]: Remove a row or column of the matrix

  • i - int
  • r - bool
>>> matrix.pop(0, False, True, 'c')
>>> popped = matrix.pop(0, False, True, 'c')
'''
    0 - Column index
    False - Pop column
    True - Check arguments
    'c' - Continue if error
'''
>>> popped
(Decimal('1.0'), Decimal('2.0'), Decimal('3.0'), Decimal('7.0'))
>>> print(matrix)
matx(
_____|__[0]__|__[1]__|__[2]__|
 (0) | '2.0' | '3.0' | '5.0' | 
 (1) | '4.0' | '4.0' | '5.0' | 
 (2) | '4.0' | '8.0' | '6.0' | 
 (3) | '5.0' | '6.0' | '7.0' | 
)

xvi. Get matx object using index slicing

>>> m = matx([[1,2,3,4],[1,2,5,6],[8,9,7,1]])
>>> m[2,1]
Decimal('9.0')
>>> m[:2]
matx(
_____|__[0]__|__[1]__|__[2]__|__[3]__|
 (0) | '1.0' | '2.0' | '3.0' | '4.0' |
 (1) | '1.0' | '2.0' | '5.0' | '6.0' |
)

>>> m[:2,1]
matx(
_____|__[0]__|
 (0) | '2.0' |
 (1) | '2.0' |
)

>>> m[:2,:1]
matx(
_____|__[0]__|
 (0) | '1.0' |
 (1) | '1.0' |
)

>>> m[:2,:3]
matx(
_____|__[0]__|__[1]__|__[2]__|
 (0) | '1.0' | '2.0' | '3.0' |
 (1) | '1.0' | '2.0' | '5.0' |
)

matutils

(c) matutils: Methods used with matx

>>> from deciml_maths.matrix import matx, matutils
Imported deciml...

i. (sm) sclrm(n, el, chk=True, ret='a') -> matx: Get a matx object with a scalar matrix

  • n - int
  • el - Decimal
>>> from deciml_maths import setpr                
>>> setpr(3)
>>> mat = matutils.sclrm(4, 12.12345, True, 'e')
'''
    4 - Nummber of rows of square matrix
    12.12345 - Diagonal values
    True - Check arguments
    'e' - Exit if error
'''
>>> print(mat)
matx(
_____|___[0]____|___[1]____|___[2]____|___[3]____|
 (0) | '12.123' |    '0.0' |    '0.0' |    '0.0' |
 (1) |    '0.0' | '12.123' |    '0.0' |    '0.0' |
 (2) |    '0.0' |    '0.0' | '12.123' |    '0.0' |
 (3) |    '0.0' |    '0.0' |    '0.0' | '12.123' |
)

ii. (sm) eqelm(m, n, i, chk=True, ret='a') -> matx: Get a matx object of matrix with equal elements

  • m - int
  • n - int
  • i - Decimal
>>> mat = matutils.eqelm(4, 3, 12.12345, True, 'e')
'''
    4 - Number of rows
    3 - Number of columns
    12.12345 - Element value
    True - Check arguments
    'e' - Exit if error
'''
>>> print(mat)
matx(
_____|___[0]____|___[1]____|___[2]____|
 (0) | '12.123' | '12.123' | '12.123' |
 (1) | '12.123' | '12.123' | '12.123' |
 (2) | '12.123' | '12.123' | '12.123' |
 (3) | '12.123' | '12.123' | '12.123' |
)

iii. *(sm) addmatx(a, b, r=False, chk=True, ret='a') -> matx: Get a matrix as a matx object for matrices of matx objects appended along row or column direction

  • a - matx
  • *b - matx
  • r - bool
>>> mat1 = matx([[1,2,3,4],[12.1234, 1.2365, 3, 4]])
>>> mat2 = matx([[0.2365, 1.23641, 4.25631, 5],[5,6,7,8]])
>>> mat3 = matx([[1,2,3,4],[2,3,4,5]])
>>> mat = matutils.addmatx(mat1, mat2, mat3, r=True, chk=True, ret='w')
'''
    mat1, mat2, mat3 - matx objects
    True - Along row
    True - Check arguments
    'w' - Wait and exit if error
'''
>>> print(mat)
matx(
_____|___[0]____|___[1]___|___[2]___|__[3]__|
 (0) |    '1.0' |   '2.0' |   '3.0' | '4.0' |
 (1) | '12.123' | '1.237' |   '3.0' | '4.0' |
 (2) |  '0.237' | '1.236' | '4.256' | '5.0' |
 (3) |    '5.0' |   '6.0' |   '7.0' | '8.0' |
 (4) |    '1.0' |   '2.0' |   '3.0' | '4.0' |
 (5) |    '2.0' |   '3.0' |   '4.0' | '5.0' |
)

>>> mat = matutils.addmatx(mat1, mat2, mat3, r=False, chk=True, ret='w')
'''
    mat1, mat2, mat3 - matx objects
    False - Along columns
    True - Check arguments
    'w' - Wait and exit if error
'''
>>> print(mat)
matx(
_____|___[0]____|___[1]___|__[2]__|__[3]__|___[4]___|___[5]___|___[6]___|__[7]__|__[8]__|__[9]__|_[10]__|_[11]__|
 (0) |    '1.0' |   '2.0' | '3.0' | '4.0' | '0.237' | '1.236' | '4.256' | '5.0' | '1.0' | '2.0' | '3.0' | '4.0' |
 (1) | '12.123' | '1.237' | '3.0' | '4.0' |   '5.0' |   '6.0' |   '7.0' | '8.0' | '2.0' | '3.0' | '4.0' | '5.0' |
)

iv. (cm) maddval(a, x, chk=True, ret='a') -> matx: Get a matrix as a matx object with a number added to all the rows in the matrix of a matx object at the first index

  • a - matx
  • x - Decimal
>>> mat = matutils.maddval(mat1, 10.1234, True, 'a')
'''
    mat1 - matx object
    10.1234 - Number
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat)
matx(
_____|___[0]____|___[1]____|___[2]___|__[3]__|__[4]__|
 (0) | '10.123' |    '1.0' |   '2.0' | '3.0' | '4.0' |
 (1) | '10.123' | '12.123' | '1.237' | '3.0' | '4.0' |
)

v. (sm) matlxtox(a, chk=True, ret='a') -> tuple[matx, ...]: Convert matx object to a tuple of matx objects with row matrix

  • a - matx
>>> a = matutils.matlxtox(mat1, True, 'a')
'''
    mat1 - matx objects
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> for i in a:
...     print(i)
... 
matx(
_____|__[0]__|__[1]__|__[2]__|__[3]__|
 (0) | '1.0' | '2.0' | '3.0' | '4.0' |
)

matx(
_____|___[0]____|___[1]___|__[2]__|__[3]__|
 (0) | '12.123' | '1.237' | '3.0' | '4.0' |
)

vi. (sm) matxtolx(a, chk=True, ret='a') -> matx: Convert a tuple of matx objects with row matrix to a matx object

  • a - matx
>>> mat = matutils.matxtolx(a, True, 'a')
'''
    a - Tuple of matx objects with row matrix
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat)
matx(
_____|___[0]____|___[1]___|__[2]__|__[3]__|
 (0) |    '1.0' |   '2.0' | '3.0' | '4.0' |
 (1) | '12.123' | '1.237' | '3.0' | '4.0' |
)

vii. (sm) gele(a, b, r=False, chk=True, ret='a') -> matx: Get the rows or columns of the matrix for a matx object as a matx object

  • a - matx
  • b - list[ int ]
  • r - bool
>>> cols = matutils.gele(mat, [0,3], False, True, 'a')
'''
    mat - matx objects
    [0,3] - column indexes
    False - Get columns
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(cols)
matx(
_____|__[0]__|___[1]____|
 (0) | '1.0' | '12.123' |
 (1) | '4.0' |    '4.0' |
)

>>> rows = matutils.gele(mat, [0], True, True, 'a')
'''
    mat - matx object
    [0] - Row indexes
    True - Get rows
    True - Check arguments
    'a' - Ask to exit if error
'''   
>>> print(rows)
matx(
_____|__[0]__|__[1]__|__[2]__|__[3]__|
 (0) | '1.0' | '2.0' | '3.0' | '4.0' |
)

viii. (cm) tpose(a, chk=True, ret='a') -> matx: Get the transpose matrix as a matx object for matrix of a matx object

>>> tmat = matutils.tpose(mat, True, 'a')
'''
    mat - matx object
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(tmat)
matx(
_____|__[0]__|___[1]____|
 (0) | '1.0' | '12.123' |
 (1) | '2.0' |  '1.237' |
 (2) | '3.0' |    '3.0' |
 (3) | '4.0' |    '4.0' |
)

ix. (cm) cofac(a, b, c, chk=True, ret='a') -> matx: Get the matrix of cofactors as a matx object for matrix of a matx object

  • a - matx
  • b - int
  • c - int
>>> cofac = matutils.cofac(mat, 0, 0, True, 'a')
Invalid command: matutils.cofac()
Error: Not a square matrix 

exit? y/n
n
>>> mat = matx([[1,2,3],[2,4,4],[1,3,5]])
>>> cofac = matutils.cofac(mat, 0, 0, True, 'a')
'''
    mat - matx object
    0 - Row index
    0 - Column index
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> cofac
Decimal('8.0')

x. (cm) dnant(a, chk=True, ret='a') -> Decimal: Get the determinant of matrix for a matx object

  • a - matx
>>> det = matutils.dnant(mat, True, 'a')
'''
    mat - matx object
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> det
Decimal('2.0')

xi. (cm) adjnt(a, chk=True, ret='a') -> matx: Get the adjoint of matrix for a matx object

  • a - matx
>>> adjmat = matutils.adjnt(mat, True, 'a')
'''
    mat - matx object
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(adjmat)
matx(
_____|__[0]___|__[1]___|__[2]___|
 (0) |  '8.0' | '-1.0' | '-4.0' |
 (1) | '-6.0' |  '2.0' |  '2.0' |
 (2) |  '2.0' | '-1.0' |  '0.0' |
)

xii. (cm) invse(a, chk=True, ret='a') -> matx: Get the inverse matrix as a matx object for matrix of a matx object

  • a - matx
>>> invmat = matutils.invse(mat, True, 'a')
'''
    mat - matx object
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(invmat)
matx(
_____|__[0]___|___[1]___|__[2]___|
 (0) |  '4.0' | '-0.50' | '-2.0' |
 (1) | '-3.0' |   '1.0' |  '1.0' |
 (2) |  '1.0' | '-0.50' |  '0.0' |
)

xiii. (cm) invsednant(a, chk=True, ret='a') -> Decimal: Get the determinant of the inverse matrix for matrix of a matx object

  • a - matx
>>> mat = matx([[1,2,3],[2.256245,4,4],[1,3.2358,5.332526]])
>>> mat.invse().dnant()                                     
Decimal('0.449')
>>> invdet = matutils.invsednant(mat, True, 'a')
'''
    mat - matx object
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> invdet
Decimal('0.449')

xiv. (cm) tform(a, b, c, d, r=False, chk=True, ret='a') -> matx: Get a matx object with matrix for matrix of a matx object after a row or column transformation

  • a - matx
  • b - int
  • c - int
  • d - Decimal

Note - Transformation is [b] -> [b] + c*[d]

>>> mat = matx([[1,2,3],[2,4,4],[1,3,5]])
>>> mat = matutils.tform(mat, 1, 2, 1.2487, False, True, 'a')
'''
    mat - matx object
    1 - Index
    2 - Index
    1.2487 - Factor
    False - Column transformation
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat)
matx(
_____|__[0]__|___[1]___|__[2]__|
 (0) | '1.0' | '5.747' | '3.0' |
 (1) | '2.0' | '8.996' | '4.0' |
 (2) | '1.0' | '9.245' | '5.0' |
)

xv. (sm) madd(a, b, sumr=None, chk=True, ret='a') -> matx | tuple[Decimal, ...]: Get the matrix as a matx object after matrix addition for matrices of two matx objects

  • a - matx
  • b - matx
  • sumr - bool/None
>>> mat1 = matx([[5,6,7],[3,4,1],[5,4,1]])
>>> mat = matutils.madd(mat, mat1, chk=True, ret='a')
'''
    mat, mat1 - matx objects
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat)
matx(
_____|__[0]__|___[1]____|__[2]___|
 (0) | '6.0' | '11.747' | '10.0' |
 (1) | '5.0' | '12.996' |  '5.0' |
 (2) | '6.0' | '13.245' |  '6.0' |
)

>>> sum_of_rows = matutils.madd(mat, mat1, False, True, 'a')
'''
    mat, mat1 - matx objects
    False - Return sum of elements at a row index in each column
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> sum_of_rows
(Decimal('45.747'), Decimal('30.996'), Decimal('35.245'))

xvi. (cm) saddcnst(a, b, r=False, sumr=None, chk=True, ret='a') -> matx | tuple[Decimal, ...]: Get the matrix as matx object after addition of a constant to each row or column in matrix of a matx object

  • a - list[ Decimal ] | tuple[Decimal, ...] | Decimal
  • b - matx
  • r - bool/None
  • sumr - bool/None
>>> mat = matutils.saddcnst(0.4826, mat, None, chk=True, ret='a')
'''
    0.4826 - Number
    mat - matx object
    None - Add to all elements
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat)
matx(
_____|___[0]___|___[1]____|___[2]____|
 (0) | '6.483' | '12.230' | '10.483' |
 (1) | '5.483' | '13.479' |  '5.483' |
 (2) | '6.483' | '13.728' |  '6.483' |
)

>>> mat = matutils.saddcnst([0.1,0.2,0.3], mat, True, chk=True, ret='a')
'''
    [0.1,0.2,0.3] - Numbers
    mat - matx object
    True - Add to rows
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat)
matx(
_____|___[0]___|___[1]____|___[2]____|
 (0) | '6.583' | '12.330' | '10.583' |
 (1) | '5.683' | '13.679' |  '5.683' |
 (2) | '6.783' | '14.028' |  '6.783' |
)

xvii. (sm) msub(a, b, sumr=None, chk=True, ret='a') -> matx | tuple[Decimal, ...]: Get the matrix as a matx object after matrix subtraction for matrices of two matx objects

  • a - matx
  • b - matx
  • sumr - bool/None
>>> mat1 = matx([[1.1234,2.2123,12.2541,3],[1,5,4,2],[3,1,2,2]])
>>> mat2 = matx([[2,3,1,1],[3,3,5,6],[2,3,1,1]])
>>> mat = matutils.msub(mat1, mat2, chk=True, ret='a')
'''
    mat1, mat2 - matx objects
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat)
matx(
_____|___[0]____|___[1]____|___[2]____|__[3]___|
 (0) | '-0.877' | '-0.788' | '11.254' |  '2.0' |
 (1) |   '-2.0' |    '2.0' |   '-1.0' | '-4.0' |
 (2) |    '1.0' |   '-2.0' |    '1.0' |  '1.0' |
)

xviii. (sm) smult(a, b, sumr=None, chk=False, ret='a') -> matx | tuple[Decimal, ...]: Get the matrix as matx object after multiplication of a number

  • a - matx
  • b - matx
  • sumr - bool/None
>>> mat = matutils.smult(0.1595, mat)
'''
    0.1595 - Number
    mat - matx object
'''
>>> print(mat)
matx(
_____|___[0]____|___[1]____|___[2]___|___[3]____|
 (0) |  '-0.14' | '-0.126' | '1.795' |  '0.319' |
 (1) | '-0.319' |  '0.319' | '-0.16' | '-0.638' |
 (2) |   '0.16' | '-0.319' |  '0.16' |   '0.16' |
)

xix. (cm) smultfac(a, b, r=True, sumr=None, chk=True, ret='a') -> matx | tuple[Decimal, ...]: Get the matrix as a matx object after multiplication of a number to each row or column in matrix of a matx object

  • a - list[ Decimal ] | tuple[Decimal, ...]
  • b - matx
  • r - bool
  • sumr - bool/None
>>> mat = matutils.smultfac([1,2,3,10], mat, False)
'''
    [1,2,3,10]
    mat
    False
'''
>>> print(mat)
matx(
_____|___[0]____|___[1]____|___[2]____|___[3]____|
 (0) | '-0.140' | '-0.252' |  '5.385' |  '3.190' |
 (1) | '-0.319' |  '0.638' | '-0.480' | '-6.380' |
 (2) |  '0.160' | '-0.638' |  '0.480' |  '1.600' |
)

xx. (cm) mmult(a, b, t=(False, False), sumr=None, chk=True, ret='a') -> matx | tuple[Decimal, ...]: Get the matrix as a matx object after matrix multiplication for matrices of two matx objects

  • a - matx
  • b - matx
  • t - tuple[bool, bool]
  • sumr - bool/None
>>> mat = matutils.mmult(mat, mat1, (False, True))
'''
    mat, mat1 - matx objects
    (False, True) - Use transpose of 'mat1'
'''
>>> print(mat)
matx(
_____|____[0]____|____[1]____|____[2]____|
 (0) |  '74.843' |  '26.520' |  '16.478' |
 (1) | '-23.969' | '-11.809' | '-14.039' |
 (2) |   '9.450' |   '2.090' |   '4.002' |
)
>>> mat = matutils.mmult(mat1, mat2, (False, True), False)
>>> mat
(Decimal('137.5470'), Decimal('96.0'), Decimal('60.0'))

xxi. (sm) melmult(a, b, t=(False, False), sumr=None, chk=True, ret='a') -> matx | tuple[Decimal, ...]: Get the matrix as a matx object after multipling the elements at the same indexes of the matrices of two matx objects

  • a - matx
  • b - matx
  • t - tuple[bool, bool]
  • sumr - bool/None
>>> mat = matutils.melmult(mat1, mat2)
'''
    mat1, mat2 - matx objects
'''
>>> print(mat)
matx(
_____|___[0]___|___[1]___|___[2]____|__[3]___|
 (0) | '2.246' | '6.636' | '12.254' |  '3.0' |
 (1) |   '3.0' |  '15.0' |   '20.0' | '12.0' |
 (2) |   '6.0' |   '3.0' |    '2.0' |  '2.0' |
)

xxii. (sm) uldcompose(a, chk=True, ret='a') -> tuple[matx, matx, matx]: Get a tuple with matx objects of upper triangular, diagonal, and lower triangular matrices for a matrix of a matx

  • a - matx
>>> u,l,d = matutils.uldcompose(matutils.gele(mat, [0,1,2], False))
'''
    matutils.gele(mat, [0,1,2], False) - matx object to decompose
'''
>>> print("{}{}{}".format(u,l,d))
matx(
_____|__[0]__|__[1]__|__[2]__|
 (0) | '0.0' | '3.0' | '6.0' |
 (1) | '0.0' | '0.0' | '3.0' |
 (2) | '0.0' | '0.0' | '0.0' |
)
matx(
_____|___[0]____|__[1]___|__[2]__|
 (0) |    '0.0' |  '0.0' | '0.0' |
 (1) |  '6.636' |  '0.0' | '0.0' |
 (2) | '12.254' | '20.0' | '0.0' |
)
matx(
_____|___[0]___|__[1]___|__[2]__|
 (0) | '2.246' | '15.0' | '2.0' |
)

xxiii. (cm) dpose(a, li, r=False, chk=True, ret='a') -> tuple[matx, ...]: Get a tuple of matrices after decomposing a matrix of a matx object along the row or column direction

  • a - matx
  • li - list[ int ] | tuple[int, ...]
  • r - bool
>>> mats = matutils.dpose(mat, [2,2])
'''
    mat - matx object
    [2,2] - Number of columns to decompose
'''
>>> for i in mats:print(i, end="")
... 
matx(
_____|___[0]___|__[1]___|__[2]__|
 (0) | '2.246' |  '3.0' | '6.0' |
 (1) | '6.636' | '15.0' | '3.0' |
)
matx(
_____|___[0]____|__[1]___|__[2]__|
 (0) | '12.254' | '20.0' | '2.0' |
 (1) |    '3.0' | '12.0' | '2.0' |
)

xix. (sm) moperate(a, chk=True, ret='a') -> matx | tuple[matx, ...]: Returns the result after performing specified operations.

  • a: tuple[str, tuple[matx|tuple, ...]]
    • 1st element is the operation to perform
    • If no operation is to be performed then the elements are matx objects
    • Operations:
      • "add": Perform addition of matrices in matx objects
      • "sub": Perform subtraction of matrices in matx objects from matrix in first matx object
      • "mul": Perform multiplication of matrices in matx objects
      • "invse": Get the inverse matrices for the matrices in matx objects
      • "lxtox": Convert matrices into row matrices of rows of matrices in matx objects
      • "xtolx": Convert row matrices in matx objects into matrix with rows as the rows in row matrices
      • "tpose": Get the transpose matrix of matrices in matx objects
>>> mat1=matx([1.2311,2.23514,3.2365])
>>> mat2=matx([2.3254,5.2364,3.2541])
>>> mat3=matx([2.3121,2.3214,5.3211])
>>> mat=matutils.moperate(('add', (('xtolx', (mat1, mat2, mat3)), ('invse', (('xtolx', (mat2, mat1, mat3)),)))), True, 'a')
'''
    ('add', (('xtolx', (mat1, mat2, mat3)), ('invse', (('xtolx', (mat2, mat1, mat3)),)))) - Operation sequence
    True - Check arguments
     'a' - Ask to exit if error
'''
>>> print(mat)
matx(
_____|___[0]___|___[1]____|___[2]___|
 (0) | '1.811' | '-0.453' | '4.518' |
 (1) | '2.449' |  '5.878' | '2.788' |
 (2) | '2.006' |  '3.209' | '5.156' |
)

melutils

(c) melutils: Methods for operations on rows/columns in matrix of a matx object

i. (sm) add(a, li, r=False, chk=True, ret='a') -> matx: Get a matx object with matrix of rows as sum of elements in rows or columns in a matrix of a matx object

  • a - matx
  • li - tuple[tuple[int, ...]] | list[list[ int ]] | 'all'
  • r - bool
>>> mat=matx([[1.0121, 2.3202, 5.3214], [2.3202, 4.2555, 6.3111], [5.3236, 3.5895, 4.2314]])
>>> mat1=melutils.add(mat, [[1,2],[0,2]], False, True, 'a')
'''
    mat - matx object
    [[1,2],[0,2]] - List of list of column indexes of columns to add
    False - For columns
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat1)
matx(
_____|___[0]___|___[1]____|___[2]___|
 (0) | '7.641' | '10.567' | '7.821' |
 (1) | '6.333' |  '8.631' | '9.555' |
)

>>> mat1=melutils.add(mat, [[1,2],[0,2]], True, True, 'a')
'''
    mat - matx object
    [[1,2],[0,2]] - List of list of row indexes of rows to add
    True - For rows
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat1)
matx(
_____|___[0]___|___[1]___|___[2]____|
 (0) | '7.644' | '7.846' | '10.542' |
 (1) | '6.336' | '5.910' |  '9.552' |
)

ii. (sm) mult(a, li, r=False, chk=True, ret='a') -> matx: Get a matx object with matrix of rows as multiplication of elements in rows or columns in a matrix of a matx object

  • a - matx
  • li - tuple[tuple[int, ...]] | list[list[ int ]] | 'all'
  • r - bool
>>> mat1=melutils.mult(mat, [[1,2],[0,2]], False, True, 'a')
'''
    mat - matx object
    [[1,2],[0,2]] - List of list of column indexes of columns to multiply
    False - For columns
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat1)
matx(
_____|___[0]____|___[1]____|___[2]____|
 (0) | '12.345' |  '26.86' | '15.189' |
 (1) |  '5.385' | '14.642' | '22.526' |
)

>>> mat1=melutils.mult(mat, [[1,2],[0,2]], True, True, 'a')
'''
    mat - matx object
    [[1,2],[0,2]] - List of list of row indexes of rows to multiply
    True - For rows
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat1)
matx(
_____|___[0]____|___[1]____|___[2]____|
 (0) | '12.352' | '15.279' | '26.702' |
 (1) |  '5.388' |  '8.329' | '22.513' |
)

iii. (sm) pow(an, a, li, r=False, chk=True, ret='a') -> matx: Get a matx object with matrix of rows as exponentiation of elements in rows or columns in a matrix of a matx object

  • an - tuple[Decimal, Decimal]
  • a - matx
  • li - tuple[int, ...] | list[ int ] | 'all'
  • r - bool
>>> mat1=melutils.pow((2, 2), mat, [0,1], False, True, 'a')
'''
    (2, 2) - Factor to multiply and power
    mat - matx object
    [0,1] - List of column indexes of columns to exponentiate
    False - For columns
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat1)
matx(
_____|___[0]___|___[1]____|___[2]____|
 (0) | '4.097' |  '21.53' | '113.38' |
 (1) | '21.53' | '72.454' | '51.552' |
)

>>> mat1=melutils.pow((2, 2), mat, [0,1], True, True, 'a')
'''
    (2, 2) - Factor to multiply and power
    mat - matx object
    [0,1] - List of row indexes of rows to exponentiate
    True - For rows
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat1)
matx(
_____|___[0]___|___[1]____|____[2]____|
 (0) | '4.097' |  '21.53' | '113.252' |
 (1) | '21.53' | '72.454' | '159.315' |
)

iv. (sm) log(an, a, li, r=False, chk=True, ret='a') -> matx: Get a matx object with matrix of rows as logarithm of elements in rows or columns in a matrix of a matx object

  • an - tuple[Decimal, Decimal]
  • a - matx
  • li - tuple[int, ...] | list[ int ] | 'all'
  • r - bool
>>> mat1=melutils.log((2, 2), mat, [0,1], True, True, 'a')
'''
    (2, 2) - Factor to multiply and base
    mat - matx object
    [0,1] - List of row indexes of rows for logarithm
    True - For rows
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat1)
matx(
_____|___[0]___|___[1]___|___[2]___|
 (0) | '1.017' | '2.214' | '3.412' |
 (1) | '2.214' | '3.089' | '3.658' |
)

>>> mat1=melutils.log((2, 2), mat, [0,1], False, True, 'a')
'''
    (2, 2) - Factor to multiply and base
    mat - matx object
    [0,1] - List of column indexes of columns for logarithm
    False - For columns
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat1)
matx(
_____|___[0]___|___[1]___|___[2]___|
 (0) | '1.017' | '2.214' | '3.413' |
 (1) | '2.214' | '3.089' | '2.844' |
)

v. (sm) expo(an, a, li, r=False, chk=True, ret='a') -> matx: Get a matx object with matrix of rows as exponentiation of a number by elements in rows or columns in a matrix of a matx object

  • an - tuple[Decimal, Decimal]
  • li - tuple[int, ...] | list[ int ] | 'all'
  • r - bool
>>> mat1=melutils.expo((2, 2), mat, [0,1], False, True, 'a')
'''
    (2, 2) - Number to exponentiate and factor to multiply
    mat - matx object
    [0,1] - List of column indexes of columns for exponentiation
    False - For columns
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat1)
matx(
_____|___[0]____|____[1]____|____[2]_____|
 (0) |  '4.067' |  '24.933' | '1604.602' |
 (1) | '24.933' | '365.063' |  '145.009' |
)

>>> mat1=melutils.expo((2, 2), mat, [0,1], True, True, 'a')
'''
    (2, 2) - Number to exponentiate and factor to multiply
    mat - matx object
    [0,1] - List of row indexes of rows for exponentiation
    True - For rows
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat1)
matx(
_____|___[0]____|____[1]____|____[2]_____|
 (0) |  '4.067' |  '24.933' | '1597.943' |
 (1) | '24.933' | '365.063' | '6303.774' |
)

vi. (sm) trig(n, a, li, r=False, f='cos', chk=True, ret='a') -> matx: Get a matx object with matrix of rows as trignometric function values for elements in rows or columns in a matrix of a matx object

  • n - Decimal
  • a - matx
  • li - tuple[int, ...] | list[ int ] | 'all'
  • r - bool
  • f - str
    • 'sin', 'cos', 'tan', 'cosec', 'sec', 'cot', 'asin', 'acos', 'atan', 'asec', 'acosec', 'acot', 'sinh', 'cosh', 'tanh', 'sech', 'cosech', 'coth'
>>> mat1=melutils.trig(2, mat, [0,1], False, 'tan', True, 'a')
'''
    2 - Factor to multiply
    mat - matx object
    [0,1] - List of column indexes of columns for trignometric operation
    False - For columns
    'tan' - Use the "tan" function
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat1)
matx(
_____|___[0]____|___[1]____|___[2]___|
 (0) | '-2.053' | '13.790' | '2.760' |
 (1) | '13.790' | '-1.294' | '1.252' |
)

>>> mat1=melutils.trig(2, mat, [0,1], False, 'sinh', False, 'a')
'''
    2 - Factor to multiply
    mat - matx object
    [0,1] - List of column indexes of columns for trignometric operation
    False - For columns
    'sinh' - Use the "sinh" function
    False - Check arguments
    'a' - Ask to exit if error
'''
>>> print(mat1)
matx(
_____|___[0]____|____[1]_____|_____[2]_____|
 (0) |  '3.718' |   '51.767' | '21054.143' |
 (1) | '51.767' | '2487.050' |   '656.454' |
)

matstat

(c) matstat: Methods for statistical analysis using matx object

>>> from deciml_maths.matrix import matstat, matx
Imported deciml...
>>> from deciml_maths import setpr
>>> setpr(3)

i. (sm) amean(a, el='row', chk=True, ret='a') -> tuple[Decimal, ...] | Decimal: Get the arithmatic mean for all rows/columns/elements of matrix in matx object

  • a - matx
  • el - str
    • 'row'/'col'/'all'
>>> mat=matx([[1.2312, 2.321, 5.3214, 3.23651, 5.2514, 5.3652, 4.32145],[12, 13.2642, 5.3251, 8.2569, 6.25412, 7.25631, 1.23651]])
>>> arith_mean_rows = matstat.amean(mat, 'row', True, 'a')
'''
    mat - matx object
    'row' - For all rows
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> arith_mean_rows
(Decimal('3.864'), Decimal('7.656'))
>>> arith_mean_cols = matstat.amean(mat, 'col', True, 'a')
'''
    mat - matx object
    'col' - For all columns
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> arith_mean_cols
(Decimal('6.616'), Decimal('7.793'), Decimal('5.323'), Decimal('5.747'), Decimal('5.753'), Decimal('6.311'), Decimal('2.779'))
>>> arith_mean = matstat.amean(mat, 'all', True, 'a')
'''
    mat - matx object
    'all' - For all elements in matrix
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> arith_mean
Decimal('5.760')

ii. gmean(a, el='row', chk=True, ret='a') -> tuple[Decimal, ...] | Decimal: Get the geometric mean for all rows/columns/elements of matrix in matx object

  • a - matx
  • el - str
    • 'row'/'col'/'all'
>>> geo_mean_rows = matstat.gmean(mat, 'row', True, 'a')
'''
    mat - matx object
    'row' - For all rows
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> geo_mean_rows
(Decimal('3.466'), Decimal('6.301'))
>>> geo_mean_cols = matstat.gmean(mat, 'col', True, 'a')
'''
    mat - matx object
    'col' - For all columns
    True - Check arguments
    'a' - Ask to exit if error
'''       
>>> geo_mean_cols
(Decimal('3.843'), Decimal('5.549'), Decimal('5.323'), Decimal('5.17'), Decimal('5.731'), Decimal('6.239'), Decimal('2.312'))
>>> geo_mean = matstat.gmean(mat, 'all', True, 'a')
'''
    mat - matx object
    'all' - For all elements in matrix
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> geo_mean
Decimal('4.671')

iii. hmean(a, el='row', chk=True, ret='a') -> tuple[Decimal, ...] | Decimal: Get the harmonic mean for all rows/columns/elements of matrix in matx object

  • a - matx
  • el - str
    • 'row'/'col'/'all'
>>> harm_mean_rows = matstat.hmean(mat, 'row', True, 'a')
'''
    mat - matx object
    'row' - For all rows
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> harm_mean_rows
(Decimal('0.426'), Decimal('0.635'))
>>> harm_mean = matstat.hmean(mat, 'all', True, 'a')
'''
    mat - matx object
    'all' - For all elements in matrix
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> harm_mean
Decimal('0.255')

iv. qmean(a, el='row', chk=True, ret='a') -> tuple[Decimal, ...] | Decimal: Get the quadratic mean of all rows/columns/elements of matrix in matx object

  • a - matx
  • el - str
    • 'row'/'col'/'all'
>>> quad_mean_rows = matstat.qmean(mat, 'row', True, 'a')
'''
    mat - matx object
    'row' - For all rows
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> quad_mean_rows
(Decimal('3.466'), Decimal('6.301'))
>>> quad_mean = matstat.qmean(mat, 'all', True, 'a')
'''
    mat - matx object
    'all' - For all elements in matrix
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> quad_mean
Decimal('4.671')

v. var(a, el='row', samp=True, chk=True, ret='a') -> tuple[Decimal, ...] | Decimal: Get the sample or population variance of all rows/columns/elements of matrix in matx object

  • a - matx
  • el - str
    • 'row'/'col'/'all'
  • samp - bool
>>> samp_var_rows = matstat.var(mat, 'row', True, True, 'a')
'''
    mat - matx object
    'row' - For all rows
    True - Sample variance
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> samp_var_rows
(Decimal('2.703'), Decimal('16.574'))
>>> popul_var = matstat.var(mat, 'all', False, True, 'a')
'''
    mat - matx object
    'all' - For all elements in matrix
    False - Population variance
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> popul_var
Decimal('11.857')

vi. sd(a, el='row', samp=True, chk=True, ret='a') -> tuple[Decimal, ...] | Decimal: Get the sample or population standard deviation for all rows/columns/elements of matrix in matx object

  • a - matx
  • el - str
    • 'row'/'col'/'all'
  • samp - bool
>>> std_dev_rows = matstat.sd(mat, 'row', True, True, 'a')
'''
    mat - matx object
    'row' - For all rows
    True - Sample standard deviation
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> std_dev_rows
(Decimal('1.644'), Decimal('4.071'))
>>> popul_std_dev = matstat.sd(mat, 'all', False, True, 'a')
'''
    mat - matx object
    'all' - For all elements in matrix
    False - Population standard deviation
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> popul_std_dev
Decimal('3.443')

vii. median(a, el='row', chk=True, ret='a') -> tuple[Decimal, ...] | Decimal

  • a - matx
  • el - str
    • 'row'/'col'/'all'
>>> median_rows = matstat.median(mat, 'row', True, 'a')
'''
    mat - matx object
    'row' - For all rows
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> median_rows
(Decimal('4.321'), Decimal('7.256'))
>>> median = matstat.median(mat, 'all', True, 'a')
'''
    mat - matx object
    'all' - For all elements in matrix
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> median
Decimal('5.323')

viii. mode(a, el='row', chk=True, ret='a') -> tuple[dict, ...] | dict

  • a - matx
  • el - str
    • 'row'/'col'/'all'
>>> mat = matx([[1,2,4,6,4,3,4,5,6,4,3,4,5,6,4,4,4],[4,5,6,23,4,65,7,4,23,4,5,6,8,6,4,2,5]])
>>> mode_rows = matstat.mode(mat, 'row', True, 'a')
'''
    mat - matx object
    'row' - For all rows
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> mode_rows
({'values': (Decimal('4.0'),), 'mode': 8}, {'values': (Decimal('4.0'),), 'mode': 5})
>>> mode = matstat.mode(mat, 'all', True, 'a')
'''
    mat - matx object
    'all' - For all elements in matrix
    True - Check arguments
    'a' - Ask to exit if error
'''
>>> mode
{'values': (Decimal('4.0'),), 'mode': 13}

Data

data

(o) data: Data object to store data values for independent (x) and dependent (y) variables

>>> from deciml_maths.data import data
>>> dat = data([[1,2,3,4],[2,3,4,5],[3,4,5,6],[5,6,7,4],[9,8,7,0]], [1,2,3,4,5])

i. (s) x_labels: Set the x labels

>>> dat.x_labels = ["A", "B", "C", "D"]

ii. (g) x_labels -> tuple[str, ...]: Get the x labels

>>> dat.x_labels
('A', 'B', 'C', 'D')

iii. (s) y_label: Set the y label

>>> dat.y_label = "Y Value"

iv. (g) y_label -> str: Get the y label

>>> dat.y_label
'Y Value'

v. (f) get_label_index(labels) -> tuple[int, ...]: Get the index

  • labels - tuple[str, ...] | list[str]
>>> dat.get_label_index(["A", "C", "D"])
'''
    ["A", "C", "D"] - List of column names
'''
[0, 2, 3]

vi. get data object using index slicing

>>> dat[:,["A","B"]]
data[
___|____A_____|____B_____||_Y Value__|
 0 |   1.0    |   2.0    ||   1.0    |
 1 |   2.0    |   3.0    ||   2.0    |
 2 |   3.0    |   4.0    ||   3.0    |
 3 |   5.0    |   6.0    ||   4.0    |
 4 |   9.0    |   8.0    ||   5.0    |
]
>>> dat[:,0]
data[
___|____A_____||_Y Value__|
 0 |   1.0    ||   1.0    |
 1 |   2.0    ||   2.0    |
 2 |   3.0    ||   3.0    |
 3 |   5.0    ||   4.0    |
 4 |   9.0    ||   5.0    |
]
>>> dat[0,:]
data[
___|____A_____|____B_____|____C_____|____D_____||_Y Value__|
 0 |   1.0    |   2.0    |   3.0    |   4.0    ||   1.0    |
]
>>> dat[1:4,:]
data[
___|____A_____|____B_____|____C_____|____D_____||_Y Value__|
 0 |   2.0    |   3.0    |   4.0    |   5.0    ||   2.0    |
 1 |   3.0    |   4.0    |   5.0    |   6.0    ||   3.0    |
 2 |   5.0    |   6.0    |   7.0    |   4.0    ||   4.0    |
]

vii. (g) data -> tuple[matx, tuple[Decimal, ...]]: Get the data as a tuple with matx object of x values and tuple of y values

>>> dat.data
(matx(
_____|__[0]__|__[1]__|__[2]__|__[3]__|
 (0) | '1.0' | '2.0' | '3.0' | '4.0' |
 (1) | '2.0' | '3.0' | '4.0' | '5.0' |
 (2) | '3.0' | '4.0' | '5.0' | '6.0' |
 (3) | '5.0' | '6.0' | '7.0' | '4.0' |
 (4) | '9.0' | '8.0' | '7.0' | '0.0' |
)
, (Decimal('1.0'), Decimal('2.0'), Decimal('3.0'), Decimal('4.0'), Decimal('5.0')))

viii. (g) datalen -> int: Get the length of data

>>> dat.datalen
5

ix. (g) xvars -> int: Get the number of x variables

>>> dat.xvars
4

x. (g) pdata: Print the data

>>> dat.pdata
data[
  0: '1.0', '2.0', '3.0', '4.0' | 1.0
  1: '2.0', '3.0', '4.0', '5.0' | 2.0
  2: '3.0', '4.0', '5.0', '6.0' | 3.0
  3: '5.0', '6.0', '7.0', '4.0' | 4.0
  4: '9.0', '8.0', '7.0', '0.0' | 5.0
]

xi. (f) getax() -> matx: Get all x values as a matx object

>>> dat.getax()
matx(
_____|__[0]__|__[1]__|__[2]__|__[3]__|
 (0) | '1.0' | '2.0' | '3.0' | '4.0' |
 (1) | '2.0' | '3.0' | '4.0' | '5.0' |
 (2) | '3.0' | '4.0' | '5.0' | '6.0' |
 (3) | '5.0' | '6.0' | '7.0' | '4.0' |
 (4) | '9.0' | '8.0' | '7.0' | '0.0' |
)

xii. (f) getay() -> tuple[Decimal, ...]: Get all y values as a tuple

>>> dat.getay()
(Decimal('1.0'), Decimal('2.0'), Decimal('3.0'), Decimal('4.0'), Decimal('5.0'))

xiii. (f) getx(li, chk=True, ret='a') -> matx: Get the x values at indexes

  • li - list[int] | tuple[int, ...]
  • chk - bool
  • ret - str
>>> dat.getx([0, 1, 3, 4])
'''
    [0, 1, 3, 4] - Row indexes
'''
matx(
_____|__[0]__|__[1]__|__[2]__|__[3]__|
 (0) | '1.0' | '2.0' | '3.0' | '4.0' |
 (1) | '2.0' | '3.0' | '4.0' | '5.0' |
 (2) | '5.0' | '6.0' | '7.0' | '4.0' |
 (3) | '9.0' | '8.0' | '7.0' | '0.0' |
)

xiv. (f) gety(li, chk=True, ret='a') -> tuple[Decimal, ...]: Get the y values at indexes

  • li - list[int] | tuple[int, ...]
  • chk - bool
  • ret - str
>>> dat.gety([0, 1, 3, 4])
'''
    [0, 1, 3, 4] - Row indexes
'''
(Decimal('1.0'), Decimal('2.0'), Decimal('4.0'), Decimal('5.0'))

xv. (f) getd(li, chk=True, ret='a') -> tuple[matx, tuple[Decimal, ...]]: Get a tuple with matx object of x values and tuple of y values for indexes

  • li - list[int] | tuple[int, ...]
  • chk - bool
  • ret - str
>>> dat.getd([0, 1, 3, 4])
'''
    [0, 1, 3, 4] - Row indexes
'''
(matx(
_____|__[0]__|__[1]__|__[2]__|__[3]__|
 (0) | '1.0' | '2.0' | '3.0' | '4.0' |
 (1) | '2.0' | '3.0' | '4.0' | '5.0' |
 (2) | '5.0' | '6.0' | '7.0' | '4.0' |
 (3) | '9.0' | '8.0' | '7.0' | '0.0' |
)
, (Decimal('1.0'), Decimal('2.0'), Decimal('4.0'), Decimal('5.0')))

xvi. (f) getlx(li, chk=True, ret='a') -> matx: Get the x values as a matx object for x variable at indexes

  • li - list[int] | tuple[int, ...]
  • chk - bool
  • ret - str
>>> dat.getlx(dat.get_label_index(["A", "C", "D"]))
'''
    dat.get_label_index(["A", "C", "D"]) - Column indexes
'''
matx(
_____|__[0]__|__[1]__|__[2]__|
 (0) | '1.0' | '3.0' | '4.0' |
 (1) | '2.0' | '4.0' | '5.0' |
 (2) | '3.0' | '5.0' | '6.0' |
 (3) | '5.0' | '7.0' | '4.0' |
 (4) | '9.0' | '7.0' | '0.0' |
)

datautils

(c) datautils: Methods to use with data object

>>> from deciml_maths.data import datautils

i. dataval(d, x, chk=True, ret='a') -> data: Add a x variable with constant value to data

  • d - data
  • x - Decimal
  • chk - bool
  • ret - str
>>> datautils.dataval(dat, 12.123)
'''
    dat - data object
    12.123 - Column's values
'''
data[
___|____0_____|____1_____|____2_____|____3_____|____4_____||____Y_____|
 0 |  12.123  |   1.0    |   2.0    |   3.0    |   4.0    ||   1.0    |
 1 |  12.123  |   2.0    |   3.0    |   4.0    |   5.0    ||   2.0    |
 2 |  12.123  |   3.0    |   4.0    |   5.0    |   6.0    ||   3.0    |
 3 |  12.123  |   5.0    |   6.0    |   7.0    |   4.0    ||   4.0    |
 4 |  12.123  |   9.0    |   8.0    |   7.0    |   0.0    ||   5.0    |
]

ii. addata(d, *a, chk=True, ret='a') -> data: Add x variables to data object

  • d - data
  • *a - matx
  • chk - bool
  • ret - str
>>> datautils.addata(dat, matx([[1],[3],[5],[7],[9]]), matx([[1,1],[2,2],[3,3],[4,4],[5,5]]))
'''
    dat - data object
    matx([[1],[3],[5],[7],[9]]), matx([[1,1],[2,2],[3,3],[4,4],[5,5]]) - matx objects
'''
data[
___|____0_____|____1_____|____2_____|____3_____|____4_____|____5_____|____6_____||____Y_____|
 0 |   1.0    |   2.0    |   3.0    |   4.0    |   1.0    |   1.0    |   1.0    ||   1.0    |
 1 |   2.0    |   3.0    |   4.0    |   5.0    |   3.0    |   2.0    |   2.0    ||   2.0    |
 2 |   3.0    |   4.0    |   5.0    |   6.0    |   5.0    |   3.0    |   3.0    ||   3.0    |
 3 |   5.0    |   6.0    |   7.0    |   4.0    |   7.0    |   4.0    |   4.0    ||   4.0    |
 4 |   9.0    |   8.0    |   7.0    |   0.0    |   9.0    |   5.0    |   5.0    ||   5.0    |
]

iii. datalx(d, li, chk=True, ret='a') -> data: Get a data object with x variables at indexes

  • d - data
  • li - list[int] | tuple[int,...]
  • chk - bool
  • ret - str
>>> datautils.datalx(dat, [0,1,3])
'''
    dat - data object
    [0,1,3] - Column indexes
'''
data[
___|____0_____|____1_____|____2_____||____Y_____|
 0 |   1.0    |   2.0    |   4.0    ||   1.0    |
 1 |   2.0    |   3.0    |   5.0    ||   2.0    |
 2 |   3.0    |   4.0    |   6.0    ||   3.0    |
 3 |   5.0    |   6.0    |   4.0    ||   4.0    |
 4 |   9.0    |   8.0    |   0.0    ||   5.0    |
]

iv. multlx(d, li, chk=True, ret='a') -> data: Get a data object with multiplication of x variables at indexes as added x variables

  • d - data
  • li - list[list[int]] | tuple[tuple[int,...]] | str
  • chk - bool
  • ret - str
>>> datautils.multlx(dat, [[0,1],[1,2]])
'''
    dat - data object
    [[0,1],[1,2]] - Columns to multiply
'''
data[
___|____0_____|____1_____|____2_____|____3_____|____4_____|____5_____||____Y_____|
 0 |   1.0    |   2.0    |   3.0    |   4.0    |   2.0    |   6.0    ||   1.0    |
 1 |   2.0    |   3.0    |   4.0    |   5.0    |   6.0    |   12.0   ||   2.0    |
 2 |   3.0    |   4.0    |   5.0    |   6.0    |   12.0   |   20.0   ||   3.0    |
 3 |   5.0    |   6.0    |   7.0    |   4.0    |   30.0   |   42.0   ||   4.0    |
 4 |   9.0    |   8.0    |   7.0    |   0.0    |   72.0   |   56.0   ||   5.0    |
]

v. aaddlx(d, li, chk=True, ret='a') -> data: Get a data object with addition of x variables at indexes as added x variables

  • d - data
  • li - list[list[int]] | tuple[tuple[int,...]] | str
  • chk - bool
  • ret - str
>>> datautils.addlx(dat, [[0,1],[1,2]])
'''
    dat - data object
    [[0,1],[1,2]] - Columns to add
'''
data[
___|____0_____|____1_____|____2_____|____3_____|____4_____|____5_____||____Y_____|
 0 |   1.0    |   2.0    |   3.0    |   4.0    |   3.0    |   5.0    ||   1.0    |
 1 |   2.0    |   3.0    |   4.0    |   5.0    |   5.0    |   7.0    ||   2.0    |
 2 |   3.0    |   4.0    |   5.0    |   6.0    |   7.0    |   9.0    ||   3.0    |
 3 |   5.0    |   6.0    |   7.0    |   4.0    |   11.0   |   13.0   ||   4.0    |
 4 |   9.0    |   8.0    |   7.0    |   0.0    |   17.0   |   15.0   ||   5.0    |
]

vi. powlx(d, an, li, chk=True, ret='a') -> data: Get a data object with exponentiated x variables as added x variables

  • d - data
  • an - tuple[Decimal, Decimal]
  • li - list[int] | tuple[int,...] | str
  • chk - bool
  • ret - str
>>> datautils.powlx(dat, (2, 3), [0,1,2])
'''
    dat - data object
    (2, 3) - Multiplication factor and exponent
    [0,1,2] - Column indexes
'''
data[
___|____0_____|____1_____|____2_____|____3_____|____4_____|____5_____|____6_____||____Y_____|
 0 |   1.0    |   2.0    |   3.0    |   4.0    |   8.0    |   64.0   |  216.0   ||   1.0    |
 1 |   2.0    |   3.0    |   4.0    |   5.0    |   64.0   |  216.0   |  512.0   ||   2.0    |
 2 |   3.0    |   4.0    |   5.0    |   6.0    |  216.0   |  512.0   |  1000.0  ||   3.0    |
 3 |   5.0    |   6.0    |   7.0    |   4.0    |  1000.0  |  1728.0  |  2744.0  ||   4.0    |
 4 |   9.0    |   8.0    |   7.0    |   0.0    |  5832.0  |  4096.0  |  2744.0  ||   5.0    |
]

vii. loglx(d, an, li, chk=True, ret='a') -> data: Get a data object with logarithm of x variables as added x variables

  • d - data
  • an - tuple[Decimal,Decimal]
  • li - list[int] | tuple[int,...] | str
  • chk - bool
  • ret - str
>>> datautils.loglx(dat, (2, 2), [0,1,2])
'''
    dat - data object
    (2, 2) - Factor and base
    [0,1,2] - Column indexes
'''
data[
___|____0_____|____1_____|____2_____|____3_____|____4_____|____5_____|____6_____||____Y_____|
 0 |   1.0    |   2.0    |   3.0    |   4.0    |   1.0    |   2.0    |  2.585   ||   1.0    |
 1 |   2.0    |   3.0    |   4.0    |   5.0    |   2.0    |  2.585   |   3.0    ||   2.0    |
 2 |   3.0    |   4.0    |   5.0    |   6.0    |  2.585   |   3.0    |  3.322   ||   3.0    |
 3 |   5.0    |   6.0    |   7.0    |   4.0    |  3.322   |  3.585   |  3.807   ||   4.0    |
 4 |   9.0    |   8.0    |   7.0    |   0.0    |   4.17   |   4.0    |  3.807   ||   5.0    |
]

viii. expolx(d, an, li, chk=True, ret='a') -> data: Get a data object with exponentiation using x variables as added x variables

  • d - data
  • an - tuple[Decimal,Decimal]
  • li - list[int] | tuple[int,...] | str
  • chk - bool
  • ret - str
>>> datautils.expolx(dat, (2, 2), [0,1,2])
'''
    dat - data object
    (2, 2) - Base and factor
    [0,1,2] - Column indexes
'''
data[
___|____0_____|____1_____|____2_____|____3_____|____4_____|____5_____|____6_____||____Y_____|
 0 |   1.0    |   2.0    |   3.0    |   4.0    |   4.0    |   16.0   |   64.0   ||   1.0    |
 1 |   2.0    |   3.0    |   4.0    |   5.0    |   16.0   |   64.0   |  256.0   ||   2.0    |
 2 |   3.0    |   4.0    |   5.0    |   6.0    |   64.0   |  256.0   |  1024.0  ||   3.0    |
 3 |   5.0    |   6.0    |   7.0    |   4.0    |  1024.0  |  4096.0  | 16384.0  ||   4.0    |
 4 |   9.0    |   8.0    |   7.0    |   0.0    | 262144.0 | 65536.0  | 16384.0  ||   5.0    |
]

ix. triglx(d, n, li, f='cos', chk=True, ret='a') -> data: Ge a data object with x variables after operation with a trignometric function as added x variables

  • d - data
  • n - Decimal
  • li - list[int] | tuple[int,...] | str
  • f - str
    • 'sin', 'cos', 'tan', 'cosec', 'sec', 'cot', 'asin', 'acos', 'atan', 'asec', 'acosec', 'acot', 'sinh', 'cosh', 'tanh', 'sech', 'cosech', 'coth'
  • chk - bool
  • ret - str
>>> datautils.triglx(dat, 2, [0,1,2], 'cos')
'''
    dat - data object
    2 - Factor
    [0,1,2] - Column indexes
    'cos' - Trignometric operation
'''
data[
___|____0_____|____1_____|____2_____|____3_____|____4_____|____5_____|____6_____||____Y_____|
 0 |   1.0    |   2.0    |   3.0    |   4.0    |  -0.416  |  -0.654  |  0.960   ||   1.0    |
 1 |   2.0    |   3.0    |   4.0    |   5.0    |  -0.654  |  0.960   |  -0.146  ||   2.0    |
 2 |   3.0    |   4.0    |   5.0    |   6.0    |  0.960   |  -0.146  |  -0.839  ||   3.0    |
 3 |   5.0    |   6.0    |   7.0    |   4.0    |  -0.839  |  0.844   |  0.137   ||   4.0    |
 4 |   9.0    |   8.0    |   7.0    |   0.0    |  0.660   |  -0.958  |  0.137   ||   5.0    |
]

Functions

axn

(o) axn: Get the object for a exponentiated variable

  • __f1 - Decimal
  • __f2 - Decimal
  • ret - str
>>> from deciml_maths.functions import axn
>>> fun = axn(2,5.5)
'''
    2 - Coefficient
    5.5 - Power
'''

i. (f) f(__a)

  • __a: The value of the variable
>>> fun.f(2)
Decimal('90.51')

ii. (f) df(__a)

  • __a: The value of the variable
  • __pr: The precision
>>> fun.df(2)
Decimal('248.901')

iii. (g) getf

>>> fun.getf
(Decimal('2.0'), Decimal('5.5'))

iv. (g) getdf

>>> fun.getdf
(Decimal('11.0'), Decimal('4.5'))

poly

(o) poly: Get the object for a polynomial function

  • *__f - tuple[Decimal,Decimal]|list[Decimal]
  • ret - str
>>> from deciml_maths.functions import poly
fun = poly((Decimal('2.0'), Decimal('3.0')), (Decimal('2.0'), Decimal('5.5')))
'''
    (Decimal('2.0'), Decimal('3.0')), (Decimal('2.0'), Decimal('5.5')) - Coefficients and exponent
'''

i. (f) f(__a)

  • __a: The value of the variable
>>> fun.f(2)
Decimal('106.51')

ii. (f) df(__a)

  • __a: The value of the variable
>>> fun.df(2)
Decimal('272.902')

iii. (g) getf

>>> fun.getf
((Decimal('2.0'), Decimal('3.0')), (Decimal('2.0'), Decimal('5.5')))

iv. (g) getdf

>>> fun.getdf
((Decimal('6.0'), Decimal('2.0')), (Decimal('11.0'), Decimal('4.5')))

apolyn

(o) apolyn: Get the object for a exponentiated polynomial function

  • __a - Decimal
  • __n - Decimal
  • *__f - tuple[Decimal,Decimal]|list[Decimal]
  • ret - str
from deciml_maths.functions import apolyn
f = apolyn('5.5', '2.5', (2.3, 4), (5, 3))
'''
    '5.5' - Coefficient
    '2.5' - Exponent
    (2.3, 4), (5, 3) - Coefficients and exponent
'''

i. (f) f(__a, __pr=getpr())

  • __a: The value of the variable
  • __pr: The precision
Decimal('284292.721')

ii. (f) df(__a, __pr=getpr())

  • __a: The value of the variable
  • __pr: The precision
Decimal('1236377.205')

iii. (g) getf

((Decimal('5.5'), Decimal('2.5')), ((Decimal('2.3'), Decimal('4.0')), (Decimal('5.0'), Decimal('3.0'))))

iv. (g) getdf

((Decimal('13.75'), Decimal('1.5')), ((Decimal('2.3'), Decimal('4.0')), (Decimal('5.0'), Decimal('3.0'))), ((Decimal('9.20'), Decimal('3.0')), (Decimal('15.0'), Decimal('2.0'))))

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deciml_mathematics-0.0.3.tar.gz (53.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

deciml_mathematics-0.0.3-py3-none-any.whl (69.3 kB view details)

Uploaded Python 3

File details

Details for the file deciml_mathematics-0.0.3.tar.gz.

File metadata

  • Download URL: deciml_mathematics-0.0.3.tar.gz
  • Upload date:
  • Size: 53.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for deciml_mathematics-0.0.3.tar.gz
Algorithm Hash digest
SHA256 a66e86127155a3efff696cb4d0ba1c6a6c8c9ed7b4d03b829c9185d45f4274b1
MD5 36fd9e439086d744ef82173c5e005aab
BLAKE2b-256 03f949c65b5e711a4dd1150ccdb0f9cb80c0842d918ea19a92f3bb820a9980a3

See more details on using hashes here.

File details

Details for the file deciml_mathematics-0.0.3-py3-none-any.whl.

File metadata

File hashes

Hashes for deciml_mathematics-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 385513985db42f69c3a07d804b527da11c5e8939a85c3f869719d62d7f71a7db
MD5 09983990540150b0cea4cc3b86281983
BLAKE2b-256 20ea413ef240f3d2dd1632b4deab4edab34a6c068b97d4771cc206b41e670beb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page