npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

matrixify.js

v1.1.3

Published

Matrices in Javascript

Readme

Matrix Class Documentation

This module defines a Matrix class that provides utility methods for basic matrix operations such as addition, subtraction, multiplication, division, exponentiation, and other matrix transformations. The class also includes methods for matrix manipulation, such as flattening the matrix, checking its properties, and updating its elements.

Methods

Constructor: constructor()

  • Initializes an empty matrix (this.matrix).
  • Usage:
    const matrix = new Matrix();

Method: add(values)

  • Adds rows of values to the matrix.
  • Parameters:
    • values: An array of arrays, where each array represents a row in the matrix.
  • Usage:
    matrix.add([[1, 2], [3, 4]]);

Method: print()

  • Prints the matrix in a tabular format to the console.
  • Usage:
    matrix.print();

Static Method: addMatrix(matrix1, matrix2)

  • Adds two matrices element-wise.
  • Parameters:
    • matrix1: The first matrix (array of arrays).
    • matrix2: The second matrix (array of arrays).
  • Returns: A new matrix representing the element-wise sum of matrix1 and matrix2.
  • Usage:
    const result = Matrix.addMatrix(matrix1, matrix2);

Static Method: subtractMatrix(matrix1, matrix2)

  • Subtracts the second matrix from the first matrix element-wise.
  • Parameters:
    • matrix1: The first matrix (array of arrays).
    • matrix2: The second matrix (array of arrays).
  • Returns: A new matrix representing the element-wise difference of matrix1 and matrix2.
  • Usage:
    const result = Matrix.subtractMatrix(matrix1, matrix2);

Static Method: multiplyMatrix(matrix1, matrix2)

  • Multiplies two matrices element-wise.
  • Parameters:
    • matrix1: The first matrix (array of arrays).
    • matrix2: The second matrix (array of arrays).
  • Returns: A new matrix representing the element-wise product of matrix1 and matrix2.
  • Usage:
    const result = Matrix.multiplyMatrix(matrix1, matrix2);

Static Method: divideMatrix(matrix1, matrix2)

  • Divides the elements of the first matrix by the corresponding elements of the second matrix element-wise.
  • Parameters:
    • matrix1: The first matrix (array of arrays).
    • matrix2: The second matrix (array of arrays).
  • Returns: A new matrix representing the element-wise quotient of matrix1 and `matrix2.
  • Usage:
    const result = Matrix.divideMatrix(matrix1, matrix2);

Static Method: powerMatrix(matrix1, matrix2)

  • Raises the elements of the first matrix to the powers of the corresponding elements of the second matrix element-wise.
  • Parameters:
    • matrix1: The first matrix (array of arrays).
    • matrix2: The second matrix (array of arrays).
  • Returns: A new matrix representing the element-wise power of matrix1 raised to matrix2.
  • Usage:
    const result = Matrix.powerMatrix(matrix1, matrix2);

Static Method: matrixMultiplication(matrix1, matrix2)

  • Performs matrix multiplication between two matrices.
  • Parameters:
    • matrix1: The first matrix (array of arrays).
    • matrix2: The second matrix (array of arrays).
  • Returns: A new matrix representing the result of the matrix multiplication of matrix1 and matrix2.
  • Usage:
    const result = Matrix.matrixMultiplication(matrix1, matrix2);

Method: firstMultiply()

  • Multiplies the elements of the first row with the corresponding elements of the first column in the matrix.
  • Returns: A new array representing the multiplication result.
  • Usage:
    const result = matrix.firstMultiply();

Method: convertToList()

  • Flattens the matrix into a one-dimensional array.
  • Returns: A one-dimensional array containing all the matrix elements.
  • Usage:
    const list = matrix.convertToList();

Method: isZeroMatrix()

  • Checks if the matrix is a zero matrix (all elements are zeros).
  • Returns: true if the matrix is a zero matrix, false otherwise.
  • Usage:
    const result = matrix.isZeroMatrix();

Method: isSquareMatrix()

  • Checks if the matrix is a square matrix (same number of rows and columns).
  • Returns: true if the matrix is square, false otherwise.
  • Usage:
    const result = matrix.isSquareMatrix();

Method: isIdentityMatrix()

  • Checks if the matrix is an identity matrix (diagonal elements are 1 and others are 0).
  • Returns: true if the matrix is an identity matrix, false otherwise.
  • Usage:
    const result = matrix.isIdentityMatrix();

Method: delete(row=undefined, column=undefined)

  • Deletes a specified row or column from the matrix.
  • Parameters:
    • row: The index of the row to be deleted (optional).
    • column: The index of the column to be deleted (optional).
  • Usage:
    matrix.delete(0, 1); // Deletes row 0 and column 1

Method: clear()

  • Clears the matrix, removing all elements.
  • Usage:
    matrix.clear();

Method: updateRow(index, value)

  • Updates a specific row in the matrix.

  • Parameters:

    • index: The index of the row to update.
    • value: The new row values.
  • Usage:

    matrix.updateRow(0, [1, 2, 3]);

    Method: reverse()

  • Reverses the entire Matrix.

  • Usage:

    matrix.reverse();

    Method: sort()

  • sorts the entire Matrix.

  • Usage:

    matrix.sort();

Method: updateColumn(index, value)

  • Updates a specific column in the matrix.
  • Parameters:
    • index: The index of the column to update.
    • value: The new values for the column.
  • Usage:
    matrix.updateColumn(1, [1, 2, 3]);

Example Usage:

// Create a new matrix
const matrix = new Matrix();

// Add rows to the matrix
matrix.add([[1, 2], [3, 4]]);

// Print the matrix
matrix.print();

// Matrix operations
const matrix1 = [[1, 2], [3, 4]];
const matrix2 = [[5, 6], [7, 8]];

// Add matrices
const sum = Matrix.addMatrix(matrix1, matrix2);
console.log(sum);

// Multiply matrices
const product = Matrix.multiplyMatrix(matrix1, matrix2);
console.log(product);

// Matrix multiplication
const multiplicationResult = Matrix.matrixMultiplication(matrix1, matrix2);
console.log(multiplicationResult);

// Flatten matrix to list
const list = matrix.convertToList();
console.log(list);