Skip to main content

A simple way to generate matrix in Python

Project description

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 matrix
  • my_matrix.display() - Prints each dimension and its content
  • my_matrix.zero() - Replaces all the values with zeros
  • my_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 :)

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

simatrix-0.0.3.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simatrix-0.0.3-py3-none-any.whl (5.4 kB view details)

Uploaded Python 3

File details

Details for the file simatrix-0.0.3.tar.gz.

File metadata

  • Download URL: simatrix-0.0.3.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.8

File hashes

Hashes for simatrix-0.0.3.tar.gz
Algorithm Hash digest
SHA256 053d96977a66ac3ebef09dc2d3763481f6670059ff05379c50b8100e886d2261
MD5 e268475457a5c75c73e5a2c5a2dab4cf
BLAKE2b-256 642bcd4d20618ab001d7246031db2d849aca0a64bb57055f60a6003979db5874

See more details on using hashes here.

File details

Details for the file simatrix-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: simatrix-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 5.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.8

File hashes

Hashes for simatrix-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fa87454d6150d4350865d512e69d31cfc7eccea0dc764e0cc0f74adffd6dd767
MD5 5a2559ac24e2dd59de9e2615ce4c93d5
BLAKE2b-256 6ec3bc4af5292f6883cbbf4ee136770b31f71a2fc182febf5586ea506248e3a4

See more details on using hashes here.

Supported by

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