Python Matrices Utilities
Project description
Matrices.py
Matrices.py is a powerful and user-friendly Python package designed for efficient manipulation and operations on matrices. Whether you're a data scientist, machine learning engineer, or mathematician, Matrices.py provides a versatile set of tools to streamline your matrix-related tasks.
✨ Key features
-
Matrix Operations
- Add matrices
- Subtract matrices
- Multiply matrices either by a scalar or another matrix
- Transpose a matrix
-
Other features are coming soon
It works with python 3.12 or later
🔧 Installation
It should work on any python3 version after the 1.10 but it's always good to have the latest version since it will be the one I'm sure it works on :)
⚙ Using PyPi
$ pip install matrices-py
📚 Usage
📄 Matrix definition
from matrices import Matrix
# Create a basic Matrix object
matrix = Matrix([
[1, 5, 3],
[5, 3, 1],
[3, 1, 5],
])
# How to get the matrix back ?
print(matrix.matrix) # Output: [[1, 5, 3], [5, 3, 1], [3, 1, 5]]
# How many columns ?
print(matrix.columns) # Output: 3
# How many rows ?
print(matrix.rows) # Output: 3
# How to get the size as a string ?
print(matrix.size) # Output: (3x3)
🧮 Matrix operations
Addition
from matrices import Matrix
a = Matrix([
[1, 5, 3],
[5, 9, 1],
[7, 1, 5],
])
b = Matrix([
[2, 8, 1],
[3, 9, 0],
[1, 8, 7],
])
c = Matrix([
[1, 5, 3]
])
# How to add two matrices
matrix = a + b
print(matrix.matrix) # Output: [[3, 13, 4], [8, 18, 1], [8, 9, 12]]
# What append if the second matrix isn't valid ?
matrix = a + c # Exception: Matrices should be the same size ((3x3) != (1x3))
Subtraction
from matrices import Matrix
a = Matrix([
[1, 5, 3],
[5, 9, 1],
[7, 1, 5],
])
b = Matrix([
[2, 8, 1],
[3, 9, 0],
[1, 8, 7],
])
c = Matrix([
[1, 5, 3]
])
# How to add two matrices
matrix = a - b
print(matrix.matrix) # Output: [[-1, -3, 2], [2, 0, 1], [6, -7, -2]]
# What append if the second matrix isn't valid ?
matrix = a + c # Exception: Matrices should be the same size ((3x3) != (1x3))
Multiplication (scalar)
from matrices import Matrix
matrix = Matrix([
[1, 5, 3],
[5, 3, 1],
[3, 1, 5],
])
scalar = 2
# How to multiply a matrix by a scalar ?
matrix *= scalar
print(matrix.matrix) # Output: [[2, 10, 6], [10, 6, 2], [6, 2, 10]]
Multiplication (matrices)
from matrices import Matrix
a = Matrix([
[1, 5, 3],
[5, 9, 1],
[7, 1, 5],
])
b = Matrix([
[2],
[3],
[1],
])
c = Matrix([
[2, 3, 1]
])
# How to multiply two matrices ?
matrix = a @ b
print(matrix.matrix) # Output: [[20], [38], [22]]
# What append if the second matrix isn't valid ?
matrix = a @ c # Exception: Matrix a should have a columns number equals to the matrix b rows number (3 != 1)
Transpose
from matrices import Matrix
matrix = Matrix([
[1, 5, 3],
[5, 9, 1],
[7, 1, 5],
])
transposed = matrix.transpose()
print(transposed.matrix) # Output: [[1, 5, 7], [5, 9, 1], [3, 1, 5]]
🍕 Contributing
All contribution are welcomed so consider looking at the source code on GitHub
🛡 License
This project is licensed under the MIT License
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
matrices_py-0.0.6.tar.gz
(5.9 kB
view details)
Built Distribution
File details
Details for the file matrices_py-0.0.6.tar.gz
.
File metadata
- Download URL: matrices_py-0.0.6.tar.gz
- Upload date:
- Size: 5.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1bdd185fb4ed65b299efdaa59d6ead692c7a498c86e5de21d122b456500786df |
|
MD5 | cd1514c917a5e80bc0794db1d73aac81 |
|
BLAKE2b-256 | ccc707a07bdfa047e9ed1a5709928373f4f7acbf75a06f69ddb10f7f5ab46d51 |
File details
Details for the file matrices_py-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: matrices_py-0.0.6-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9211d4e5cfab50d12280539e5d39471ca490d9ae95513b69bf8eff843e530613 |
|
MD5 | eb6cac07eb63debf56c299e1817e98d0 |
|
BLAKE2b-256 | 6fa52f0c3b7b98572946a04aa36527fb734e4963996b15bc9f3630aaa9073693 |