Skip to main content

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.

GitHub License GitHub Workflow Status (with event) PyPI - Downloads GitHub Repo stars

✨ 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 hashes)

Uploaded Source

Built Distribution

matrices_py-0.0.6-py3-none-any.whl (4.1 kB view hashes)

Uploaded Python 3

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