Skip to main content

Turing college DE 2.1 coursework for Matrix operations: transform, window and cross-correlation using Python standard library.

Project description

Contents

Overview

This library offers transpose2d, window1d and convolution2d functions to perform 2D matrix creation, transposition and cross-correlation, and 1D array windowing.These functions are particularly useful for machine learning applications.

Prerequisites

Python 3.10 or newer. Numpy 1.26.1 or newer.

Custom Generic Types

Within this library, there are three custom generic types to streamline function signatures and maintain type consistency, which can be enforced by MyPy:

  • Matrix: Represents a 2D list of floats and is bound to List[List[float]].
  • Array1D: Represents a 1D array, which can either be a Python list or a 1D numpy array. It is defined as TypeVar("Array1D", List[float], np.ndarray).
  • Matrix2D: Represents a 2D numpy array and is bound to np.ndarray.

Installation

Package can be reached manually at PyPi.

The library can be installed directly from PyPi:

pip install turing_21_matrix_operations

Functions

Create Random Matrix

The create_random_matrix function generates a matrix filled with random numbers between 0 and 10.

Arguments

  • rows (int): Number of rows in the matrix.
  • columns (int): Number of columns in the matrix.

Returns

  • Matrix: 2D list of random floats.

Usage:

from turing_21_matrix_operations import create_random_matrix
matrix = create_random_matrix(3, 4)
print(matrix)

Transpose2D

The transpose2d function is designed to transpose a 2D matrix by swapping its rows and columns.

Arguments

  • input_matrix (Matrix): 2D list to be transposed.

Returns

  • Matrix: Transposed 2D list.
from turing_21_matrix_operations import transpose2d
matrix = [[1, 2], [3, 4], [5, 6]]
transposed = transpose2d(input_matrix=matrix)
print(transposed)

Window1D

The window1d function creates overlapping windows of a given size from a 1D list or numpy array.

Arguments

  • input_array (Array1D): 1D list or numpy array.
  • size (int): Desired window size.
  • shift (int, optional): Window shift size. Default is 1.
  • stride (int, optional): Window stride size. Default is 1.

Returns

  • List[Array1D]: List of 1D windows.
from turing_21_matrix_operations import window1d
input_array = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
windows = window1d(input_array=input_array, size=2, shift=2, stride=2)
print(windows)

Convolution2D

The convolution2d function performs 2D convolution using a given kernel.

Arguments

  • input_matrix (Matrix2D): 2D numpy array input matrix.
  • kernel (Matrix2D): 2D numpy array convolution kernel.
  • stride (int, optional): Convolution stride. Default is 1. Returns
  • Matrix2D: Convolved 2D numpy array.
from turing_21_matrix_operations import convolution2d
input_matrix = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
kernel = np.array([[1, 0], [0, -1]])
convolved = convolution2d(input_matrix=input_matrix, kernel=kernel)
print(convolved)

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

turing_21_matrix_operations-0.1.5.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

turing_21_matrix_operations-0.1.5-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file turing_21_matrix_operations-0.1.5.tar.gz.

File metadata

  • Download URL: turing_21_matrix_operations-0.1.5.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.6.1 CPython/3.10.9 Darwin/22.6.0

File hashes

Hashes for turing_21_matrix_operations-0.1.5.tar.gz
Algorithm Hash digest
SHA256 fc581bd231c21e01df9515e4af6f9cfc479ce97a85471bb94a1c622b4b79d4b8
MD5 6e497dff3684a4eb398ecb6ec7670e5b
BLAKE2b-256 9ed2bf6752df1b5bbf968368af99c9a09f2b6ac56b86d8957eee1751c5328a1e

See more details on using hashes here.

File details

Details for the file turing_21_matrix_operations-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for turing_21_matrix_operations-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 09bdf144a93a1e4c7c51e6e5e1a0f0643509fd40872136bf52e0683a817e2382
MD5 4ab8a8e8a9cfb41da36f263abad335e6
BLAKE2b-256 8580cc78ec67a6db40a7fc79334d54ecc2672ad95bc3e2d98553b8f3a6692d7e

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