matlib


Namematlib JSON
Version 0.1.2 PyPI version JSON
download
home_page
Summary
upload_time2023-09-14 13:49:06
maintainer
docs_urlNone
authorDenis Demenkov
requires_python>=3.10,<4.0
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # MATLIB

MatLib is a little python 2D-matrix-handling library. The following documentation will guide you through!

### Getting started:
```
pip install matlib

export n_digits=2 # precision: Optional[int], default is 3
```

## Standard operations:
```
import matlib as ml

a = ml.Matrix([
    [1, 1],
    [1, 1],
    [1, 1],
    [1, 1]
])

b = ml.Matrix([
    [2, 2],
    [2, 2],
    [2, 2],
    [2, 2]
])

print(a) # casting types

# [[1.00, 1.00]
#  [1.00, 1.00]
#  [1.00, 1.00]
#  [1.00, 1.00]]
```
```
print(a + b) # +, -, *, /, //, %

# [[3.00, 3.00]
#  [3.00, 3.00]
#  [3.00, 3.00]
#  [3.00, 3.00]]
```

```
print(a - 100) # +, -, *, /, //, %

# [[-99.00, -99.00]
#  [-99.00, -99.00]
#  [-99.00, -99.00]
#  [-99.00, -99.00]]
```

```
a *= 2.5 # inplace
print(a)

# [[2.50, 2.50]
#  [2.50, 2.50]
#  [2.50, 2.50]
#  [2.50, 2.50]]
```

### Exponentiation:
```
import matlib as ml

a = ml.Matrix([
    [2, 2],
    [2, 2]
])

print(a ** 3) # int

# [[32.00, 32.00]
#  [32.00, 32.00]]
```

### Matrix multiplication:
```
import matlib as ml

a = ml.Matrix([
    [2, 2],
    [2, 2],
    [2, 2],
    [2, 2]
])

b = ml.Matrix([
    [3, 3, 3, 3],
    [3, 3, 3, 3]
])

print(a @ b)

# [[12.00, 12.00, 12.00, 12.00]
#  [12.00, 12.00, 12.00, 12.00]
#  [12.00, 12.00, 12.00, 12.00]
#  [12.00, 12.00, 12.00, 12.00]]
```

### Transponing:
```
import matlib as ml

a = ml.Matrix([
    [2, 2],
    [2, 2],
    [2, 2],
    [2, 2]
])

print(a.T)

# [[2.00, 2.00, 2.00, 2.00]
#  [2.00, 2.00, 2.00, 2.00]]
```

### Getting the size:
```
import matlib as ml

a = ml.Matrix([
    [2, 2],
    [2, 2],
    [2, 2],
    [2, 2]
])

print(a.size)

# (4, 2)
```

## The functions:

#### 1. Calculating the determinant of the matrix:

**func:** det(*matrix: ml.Matrix*) -> *float*

```
import matlib as ml

a = ml.Matrix([
    [2, 2],
    [2, 2]
])

b = ml.det(a)
print(b)

# 0.0
```

#### 2. Matrix multiplication:
**func:** mul(*matrix_1: ml.Matrix,
               matrix_2: ml.Matrix*
               ) -> *ml.Matrix*

```
import matlib as ml

a = ml.Matrix([
    [2, 2],
    [2, 2],
    [2, 2],
    [2, 2]
])

b = ml.Matrix([
    [3, 3, 3, 3],
    [3, 3, 3, 3]
])

c = ml.mul(a, b)
print(c)

# [[12.00, 12.00, 12.00, 12.00]
#  [12.00, 12.00, 12.00, 12.00]
#  [12.00, 12.00, 12.00, 12.00]
#  [12.00, 12.00, 12.00, 12.00]]
```

#### 3. Matrix exponentiation:
**func:** pow(*matrix: ml.Matrix,
              exp: int = 1*
              ) -> *ml.Matrix*
```
import matlib as ml

a = ml.Matrix([
    [2, 2],
    [2, 2]
])

b = ml.pow(a, 3)
print(b)

# [[32.00, 32.00]
#  [32.00, 32.00]]

```

#### 4. Mqtrix transposing:
**func:** transpose(*matrix: ml.Matrix*) -> *ml.Matrix*
```
import matlib as ml

a = ml.Matrix([
    [2, 2],
    [2, 2],
    [2, 2],
    [2, 2]
])

b = transpose(a)
print(b)

# [[2.00, 2.00, 2.00, 2.00]
#  [2.00, 2.00, 2.00, 2.00]]
```

#### 5. Least Squares method:

**func:** least_squares(*matrix: ml.Matrix,
                        matrix_ans: ml.Matrix*
                        ) -> *ml.Matrix*

Finds an approximate solution for a system of linear equations.

```
import matlib as ml

a = ml.Matrix([
    [1, 1],
    [2, 1],
    [1, 5],
    [4, 1]
])

b = ml.Matrix([    
    [1],
    [4],
    [3],
    [7]
])

c = ml.least_squares(a, b)
print(c)

# [[1.69]
#  [0.24]]
```

#### 6. Gaussian Elimination method:

**func:** gaussian_elimination(*matrix: ml.Matrix,
                                matrix_ans: ml.Matrix*
                                ) -> *ml.Matrix*

Solves a system of linear equations using the Gaussian Elimination method. The program responds whether the answer to the system exists, does not exist or is an infinite amount of answers.

```
import matlib as ml

a = ml.Matrix([
    [3, 1, -2, 1],
    [2, 3, -1, 2],
    [1, -2, 2, -1],
    [1, 3, -1, 1]
    
])

b = ml.Matrix([
    [5],
    [4],
    [4],
    [0]
])

c = ml.gaussian_elimination(a, b)
print(c)

# [[ 2.00]
#  [-1.00]
#  [ 1.00]
#  [ 2.00]]

print(a @ c) # checking the answer

# [[5.00]
#  [4.00]
#  [4.00]
#  [0.00]]
```

```
a = ml.Matrix([
    [2, -4],
    [-3, 6],
])

b = ml.Matrix([
    [-1],
    [2]
])

c = gaussian_elimination(a, b)
print(c)

# System of equations cannot be solved
# [[]]
```
            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "matlib",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.10,<4.0",
    "maintainer_email": "",
    "keywords": "",
    "author": "Denis Demenkov",
    "author_email": "deniska_demenkov@mail.ru",
    "download_url": "https://files.pythonhosted.org/packages/f4/7b/56ee37cfddc71898610e485ce8a5154e9ff119a3742b014ffbde3c1cf623/matlib-0.1.2.tar.gz",
    "platform": null,
    "description": "# MATLIB\n\nMatLib is a little python 2D-matrix-handling library. The following documentation will guide you through!\n\n### Getting started:\n```\npip install matlib\n\nexport n_digits=2 # precision: Optional[int], default is 3\n```\n\n## Standard operations:\n```\nimport matlib as ml\n\na = ml.Matrix([\n    [1, 1],\n    [1, 1],\n    [1, 1],\n    [1, 1]\n])\n\nb = ml.Matrix([\n    [2, 2],\n    [2, 2],\n    [2, 2],\n    [2, 2]\n])\n\nprint(a) # casting types\n\n# [[1.00, 1.00]\n#  [1.00, 1.00]\n#  [1.00, 1.00]\n#  [1.00, 1.00]]\n```\n```\nprint(a + b) # +, -, *, /, //, %\n\n# [[3.00, 3.00]\n#  [3.00, 3.00]\n#  [3.00, 3.00]\n#  [3.00, 3.00]]\n```\n\n```\nprint(a - 100) # +, -, *, /, //, %\n\n# [[-99.00, -99.00]\n#  [-99.00, -99.00]\n#  [-99.00, -99.00]\n#  [-99.00, -99.00]]\n```\n\n```\na *= 2.5 # inplace\nprint(a)\n\n# [[2.50, 2.50]\n#  [2.50, 2.50]\n#  [2.50, 2.50]\n#  [2.50, 2.50]]\n```\n\n### Exponentiation:\n```\nimport matlib as ml\n\na = ml.Matrix([\n    [2, 2],\n    [2, 2]\n])\n\nprint(a ** 3) # int\n\n# [[32.00, 32.00]\n#  [32.00, 32.00]]\n```\n\n### Matrix multiplication:\n```\nimport matlib as ml\n\na = ml.Matrix([\n    [2, 2],\n    [2, 2],\n    [2, 2],\n    [2, 2]\n])\n\nb = ml.Matrix([\n    [3, 3, 3, 3],\n    [3, 3, 3, 3]\n])\n\nprint(a @ b)\n\n# [[12.00, 12.00, 12.00, 12.00]\n#  [12.00, 12.00, 12.00, 12.00]\n#  [12.00, 12.00, 12.00, 12.00]\n#  [12.00, 12.00, 12.00, 12.00]]\n```\n\n### Transponing:\n```\nimport matlib as ml\n\na = ml.Matrix([\n    [2, 2],\n    [2, 2],\n    [2, 2],\n    [2, 2]\n])\n\nprint(a.T)\n\n# [[2.00, 2.00, 2.00, 2.00]\n#  [2.00, 2.00, 2.00, 2.00]]\n```\n\n### Getting the size:\n```\nimport matlib as ml\n\na = ml.Matrix([\n    [2, 2],\n    [2, 2],\n    [2, 2],\n    [2, 2]\n])\n\nprint(a.size)\n\n# (4, 2)\n```\n\n## The functions:\n\n#### 1. Calculating the determinant of the matrix:\n\n**func:** det(*matrix: ml.Matrix*) -> *float*\n\n```\nimport matlib as ml\n\na = ml.Matrix([\n    [2, 2],\n    [2, 2]\n])\n\nb = ml.det(a)\nprint(b)\n\n# 0.0\n```\n\n#### 2. Matrix multiplication:\n**func:** mul(*matrix_1: ml.Matrix,\n               matrix_2: ml.Matrix*\n               ) -> *ml.Matrix*\n\n```\nimport matlib as ml\n\na = ml.Matrix([\n    [2, 2],\n    [2, 2],\n    [2, 2],\n    [2, 2]\n])\n\nb = ml.Matrix([\n    [3, 3, 3, 3],\n    [3, 3, 3, 3]\n])\n\nc = ml.mul(a, b)\nprint(c)\n\n# [[12.00, 12.00, 12.00, 12.00]\n#  [12.00, 12.00, 12.00, 12.00]\n#  [12.00, 12.00, 12.00, 12.00]\n#  [12.00, 12.00, 12.00, 12.00]]\n```\n\n#### 3. Matrix exponentiation:\n**func:** pow(*matrix: ml.Matrix,\n              exp: int = 1*\n              ) -> *ml.Matrix*\n```\nimport matlib as ml\n\na = ml.Matrix([\n    [2, 2],\n    [2, 2]\n])\n\nb = ml.pow(a, 3)\nprint(b)\n\n# [[32.00, 32.00]\n#  [32.00, 32.00]]\n\n```\n\n#### 4. Mqtrix transposing:\n**func:** transpose(*matrix: ml.Matrix*) -> *ml.Matrix*\n```\nimport matlib as ml\n\na = ml.Matrix([\n    [2, 2],\n    [2, 2],\n    [2, 2],\n    [2, 2]\n])\n\nb = transpose(a)\nprint(b)\n\n# [[2.00, 2.00, 2.00, 2.00]\n#  [2.00, 2.00, 2.00, 2.00]]\n```\n\n#### 5. Least Squares method:\n\n**func:** least_squares(*matrix: ml.Matrix,\n                        matrix_ans: ml.Matrix*\n                        ) -> *ml.Matrix*\n\nFinds an approximate solution for a system of linear equations.\n\n```\nimport matlib as ml\n\na = ml.Matrix([\n    [1, 1],\n    [2, 1],\n    [1, 5],\n    [4, 1]\n])\n\nb = ml.Matrix([    \n    [1],\n    [4],\n    [3],\n    [7]\n])\n\nc = ml.least_squares(a, b)\nprint(c)\n\n# [[1.69]\n#  [0.24]]\n```\n\n#### 6. Gaussian Elimination method:\n\n**func:** gaussian_elimination(*matrix: ml.Matrix,\n                                matrix_ans: ml.Matrix*\n                                ) -> *ml.Matrix*\n\nSolves a system of linear equations using the Gaussian Elimination method. The program responds whether the answer to the system exists, does not exist or is an infinite amount of answers.\n\n```\nimport matlib as ml\n\na = ml.Matrix([\n    [3, 1, -2, 1],\n    [2, 3, -1, 2],\n    [1, -2, 2, -1],\n    [1, 3, -1, 1]\n    \n])\n\nb = ml.Matrix([\n    [5],\n    [4],\n    [4],\n    [0]\n])\n\nc = ml.gaussian_elimination(a, b)\nprint(c)\n\n# [[ 2.00]\n#  [-1.00]\n#  [ 1.00]\n#  [ 2.00]]\n\nprint(a @ c) # checking the answer\n\n# [[5.00]\n#  [4.00]\n#  [4.00]\n#  [0.00]]\n```\n\n```\na = ml.Matrix([\n    [2, -4],\n    [-3, 6],\n])\n\nb = ml.Matrix([\n    [-1],\n    [2]\n])\n\nc = gaussian_elimination(a, b)\nprint(c)\n\n# System of equations cannot be solved\n# [[]]\n```",
    "bugtrack_url": null,
    "license": "",
    "summary": "",
    "version": "0.1.2",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b5c15141b518a12f366917fdae938f7265104102ce70e2c425277c2383f36b4c",
                "md5": "abc0deb8a8f5067b89198261d0e59a64",
                "sha256": "49cfbdb941870653016eef7f3df15b5f3dcc2880affad716959c9c3ad8a0bc71"
            },
            "downloads": -1,
            "filename": "matlib-0.1.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "abc0deb8a8f5067b89198261d0e59a64",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10,<4.0",
            "size": 7237,
            "upload_time": "2023-09-14T13:49:05",
            "upload_time_iso_8601": "2023-09-14T13:49:05.097537Z",
            "url": "https://files.pythonhosted.org/packages/b5/c1/5141b518a12f366917fdae938f7265104102ce70e2c425277c2383f36b4c/matlib-0.1.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f47b56ee37cfddc71898610e485ce8a5154e9ff119a3742b014ffbde3c1cf623",
                "md5": "0a8f42231d156c94d54a771006d2fc2b",
                "sha256": "c7c44e49d22ed3d5b3563c99863d8437961820a3173abc6e15b48d53c3d3370f"
            },
            "downloads": -1,
            "filename": "matlib-0.1.2.tar.gz",
            "has_sig": false,
            "md5_digest": "0a8f42231d156c94d54a771006d2fc2b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10,<4.0",
            "size": 6947,
            "upload_time": "2023-09-14T13:49:06",
            "upload_time_iso_8601": "2023-09-14T13:49:06.503847Z",
            "url": "https://files.pythonhosted.org/packages/f4/7b/56ee37cfddc71898610e485ce8a5154e9ff119a3742b014ffbde3c1cf623/matlib-0.1.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-14 13:49:06",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "matlib"
}
        
Elapsed time: 0.11409s