Skip to main content

This package performs basic algebraic operations

Project description

Basic algebra for Machine Learning

This package performs basic operations between two matrices that are used in the field of machine learning such as: addition, subtraction, multiplication and division. It can also perform single matrix operations such as: dot product, inverse matrix finding and determinant.

Installation

Run the following command in your terminal:

$ pip install -i https://test.pypi.org/simple/ basic-algebra-ml==0.0.1 

Usage

The package is composed of two classes:

1) Basic_Operations

Parent class that has the following methods:
  • check_type_matrix: checks if the parameters are a matrix of type <<numpy.ndarray>>.

  • addition: adds two matrices together. For example:

# Declare the matrix
[In]:   from basic_operations import Basic_Operations

        # Declare the matrix
        matrix1 = ([1, 6, 5], [6, 14, 34], [21, 12, 4])
        matrix2 = ([3, 2, 54], [21, 12, 9], [1, 6, 5])

        # Instantiate the class
        test = Basic_Operations(matrix1, matrix2)


        print(test.addition())

[Out]:  [[ 4.  8. 59.]
        [27. 26. 43.]
        [22. 18.  9.]]

  • subtraction: subtraction of two matrices. With the matrices of the previous example, then we have the following result:

[In]:   print(test.subtraction())

[Out]:  [[ -2.   4. -49.]
        [-15.   2.  25.]
        [ 20.   6.  -1.]]


  • multiplication: multiply two matrices.

Note: Remember that to perform multiplication between matrices the number of rows must match the number of columns.

[In]:   matrix3 = ([8, 56, 7], [6, 14, 34], [9, 63, 5])
        matrix4 = ([36, 1, 2], [94, 9, 12], [3, 66, 1])

        test2 = Basic_Operations(matrix3, matrix4)

        print(test2.multiplication())

[Out]:  [[ 288.   56.   14.]
        [ 564.  126.  408.]
        [  27. 4158.    5.]]

Note the following example where the dimensions do not match between more matrices. The program will give a message indicating the error.

[In]:   matrix3 = ([8, 56, 7], [6, 14, 34], [9, 63, 5])
        matrix4 = ([36, 1, 2], [94, 9, 12])

        print(test2.multiplication())

[Out]:  Error: operands could not be broadcast together with shapes (3,3) (2,3)


  • division: divide two matrices. See the following example:

Below are several examples of how you can use this package:

[In]:   print(test2.division())

[Out]:  [[ 0.22222222 56.          3.5       ]
        [ 0.06382979  1.55555556  2.83333333]
        [ 3.          0.95454545  5.        ]]


  • dot: Dot product of two arrays. See the following example:
[In]:   matrix5 = ([8, 56, 7], [6, 14, 34], [9, 63, 5])
        matrix6 = ([3, 2, 54], [21, 12, 9], [1, 6, 5])

        test3 = Basic_Operations(matrix5, matrix6)

        print(test3.dot())

[Out]:  [[1207.  730.  971.]
        [ 346.  384.  620.]
        [1355.  804. 1078.]]

2) Operations_One_Matrix:

Child class that inherits from Basic_Operations. With this class you can perform the following operations with a matrix:

  • scalar: multiply a matrix by a scalar
[In]:   from matrix_manipulations import Operations_One_Matrix


        matrix = ([36, 1, 2], [94, 9, 12], [3, 66, 1])

        test = Operations_One_Matrix(matrix)

        print(test.scalar(2))


[Out]:  [[ 72.   2.   4.]
        [188.  18.  24.]
        [  6. 132.   2.]]
  • shape: checks the dimensions of a matrix.
[In]:   print(test.scalar(2))


[Out]:  (3, 3)
  • inverse: calculate the inverse of a matrix

  • transpose: Invert or permute the axes of a matrix

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

algebraML-0.0.5.tar.gz (3.7 kB view details)

Uploaded Source

Built Distribution

algebraML-0.0.5-py3-none-any.whl (3.4 kB view details)

Uploaded Python 3

File details

Details for the file algebraML-0.0.5.tar.gz.

File metadata

  • Download URL: algebraML-0.0.5.tar.gz
  • Upload date:
  • Size: 3.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for algebraML-0.0.5.tar.gz
Algorithm Hash digest
SHA256 805cc5ecd759e93023590ef64c5df1b4387f60538fb55eb36f19c3c6ca25efcd
MD5 22cf429b40c8b5f8f747ddb78ef6e5d5
BLAKE2b-256 893aa915ab85adbd570ed26324ae65d78d084da2431f130b9d57fa5e4298f6a5

See more details on using hashes here.

File details

Details for the file algebraML-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: algebraML-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 3.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.24.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for algebraML-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 4a602412082cb1c11c447f40b1d6fef4f09814372c6043761fd9d855b7b36ae4
MD5 b68426da587b45d9bbf603d00c1b4611
BLAKE2b-256 4fbb37a2b34f738f27f94d425adc2e9bf3482f3981ba05571e639bf5c68a3892

See more details on using hashes here.

Supported by

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