Simatrix
A simple way to generate matrix in Python.
This module provides a simple way to generate a matrix (multidimensional list). Its shape is similar in design to a cube or numpy ndarray model, with the values of either integers or floats. The module is based on python's built-in list and therefore all the list methods are applicable, as well as a few custom ones, designed for the module.
Some of the common uses are:
- 3D positioning
- Serialised data collection
- An inventory
Quick Start
Install the package from pip
pip install simatrix
Import the matrix module
import simatrix.matrix as sim
Create your first matrix. Example below has 3 dimensions with 4 rows and 5 columns in each, and the value of 1 filled in every cell.
my_matrix = sim.Matrix(3, 4, 5, 1)
The matrix can be navigated through using all three dimensions - my_matrix[0][0][0],
and is zero indexed like a standard python list.
Methods
my_matrix.inspect()- Prints the size of the matrixmy_matrix.display()- Prints each dimension and its contentmy_matrix.zero()- Replaces all the values with zerosmy_matrix.set_values()- Replaces all the values with a given integer or float
Example
Code:
# Daily temperature log
import simatrix.matrix as sim
from datetime import datetime as dt
# Get current date information and turn into an index
today = dt.today()
month_id = today.month-1
day_id = today.day-1
hour_id = today.hour-1
# Create matrix with a dimension for each month of the year, row for every day of the month and column for each hour
temperatures = sim.Matrix(12, 31, 24)
# Inspect the size
temperatures.inspect()
# Get current temperature reading in Celsius (hardoced value for the example purposes)
current_temp = 28
# Set the temperature value into. In real life you'd have an hourly reading mechanism instead
temperatures[month_id][day_id][hour_id] = current_temp
# Display current month's data
temperatures.display(month_id)
Output:
Matrix objected has been created
--------------
Dimensions: 12
Rows: 31
Columns: 24
Total number of cells: 8928
--------------
[0, 0, 0, 0, 0, ... 0, 0, 0, 0, 0]
...
[0, 0, 0, 0, 0, ... 0, 0, 0, 28, 0]
...
[0, 0, 0, 0, 0, ... 0, 0, 0, 0, 0]
License
MIT License. Free to use in all projects. Any credit to my git account would be great and please consider giving this project a star :)
Metadata
Release files for simatrix 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| simatrix-0.0.3.tar.gz | 4.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| simatrix-0.0.3-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 10.1 kB
Release files / simatrix-0.0.3.tar.gz
| Download URL | simatrix-0.0.3.tar.gz |
|---|---|
| Size | 4.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
053d96977a66ac3ebef09dc2d3763481f6670059ff05379c50b8100e886d2261
|
|
BLAKE2b-256 checksum How to use checksums |
642bcd4d20618ab001d7246031db2d849aca0a64bb57055f60a6003979db5874
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.8
|
Release files / simatrix-0.0.3-py3-none-any.whl
| Download URL | simatrix-0.0.3-py3-none-any.whl |
|---|---|
| Size | 5.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
fa87454d6150d4350865d512e69d31cfc7eccea0dc764e0cc0f74adffd6dd767
|
|
BLAKE2b-256 checksum How to use checksums |
6ec3bc4af5292f6883cbbf4ee136770b31f71a2fc182febf5586ea506248e3a4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.8
|