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

@smockle/matrix

v5.0.2

Published

Single and multi dimensional matrices and matrix functions.

Downloads

58

Readme

npm codecov

matrix

Single or multi dimensional matrices and matrix functions.

Installation

Run npm install --save @smockle/matrix to add matrix to your project.

Usage

import Matrix from '@smockle/matrix'

// 1x1 Matrix
const m11 = Matrix([3])

// 1x3 Matrix
const m13 = Matrix([1, 2, 3])

// 3x1 Matrix
const m31 = Matrix([[1], [2], [3]])

API Reference

Matrix ⏏

Kind: Exported class

new Matrix(x)

Creates a Matrix

Returns: Matrix - Single or multi dimensional matrix
Throws:

  • TypeError Argument x must be a number or number array

| Param | Type | Description | | ----- | -------------------------------------------------------- | ------------------------- | | x | number | Array.<number> | Values to store in matrix |

matrix.countRows() ⇒ number

Counts rows in this matrix

Kind: instance method of Matrix
Returns: number - Number of rows

matrix.countColumns() ⇒ number

Counts columns in this matrix

Kind: instance method of Matrix
Returns: number - Number of columns

matrix.addable(y) ⇒ boolean

Determines whether this matrix can be summed

Kind: instance method of Matrix
Returns: boolean - Whether this matrix can be summed (using matrix addition)

| Param | Type | Description | | ----- | ------------------- | --------------- | | y | Matrix | Matrix to check |

matrix.add(y) ⇒ Matrix

Adds this matrix using matrix addition

Kind: instance method of Matrix
Returns: Matrix - New matrix with the summation

| Param | Type | Description | | ----- | ------------------- | ------------- | | y | Matrix | Matrix to add |

matrix.multipliable(y) ⇒ boolean

Determines whether this matrix can be multiplied

Kind: instance method of Matrix
Returns: boolean - Whether two matrices can be summed (using matrix multiplication)

| Param | Type | Description | | ----- | ------------------- | --------------- | | y | Matrix | Matrix to check |

matrix.multiply(y) ⇒ Matrix

Calculates the dot product of this matrix

Kind: instance method of Matrix
Returns: Matrix - New matrix with the dot product

| Param | Type | Description | | ----- | ------------------- | ------------------ | | y | Matrix | Matrix to multiply |

matrix.transpose() ⇒ Matrix

Calculates the transpose of this matrix

Kind: instance method of Matrix
Returns: Matrix - New matrix with the transpose

matrix.invert() ⇒ Matrix

Inverts this matrix

Kind: instance method of Matrix
Returns: Matrix - Matrix inverse

matrix.map() ⇒ Matrix

Maps over this matrix

Kind: instance method of Matrix
Returns: Matrix - Matrix inverse

matrix.valueOf() ⇒ number | Array.<number>

Returns the number or number array value

Kind: instance method of Matrix
Returns: number | Array.<number> - Number of number array value

matrix.inspect() ⇒ string

Formats and prints the matrix value

Kind: instance method of Matrix
Returns: string - Formatted matrix value

inspect~padding : string

Output array filled with zeroes

Kind: inner constant of inspect

Matrix.addable(x, y) ⇒ boolean

Determines whether two matrices can be summed

Kind: static method of Matrix
Returns: boolean - Whether two matrices can be summed (using matrix addition)

| Param | Type | Description | | ----- | ------------------- | --------------- | | x | Matrix | Matrix to check | | y | Matrix | Matrix to check |

Matrix.add(x, y) ⇒ Matrix

Adds two matrices using matrix addition

Kind: static method of Matrix
Returns: Matrix - New matrix with the summation
Throws:

  • TypeError Matrices are not addable

| Param | Type | Description | | ----- | ------------------- | ------------- | | x | Matrix | Matrix to add | | y | Matrix | Matrix to add |

Matrix.multipliable(x, y) ⇒ boolean

Determines whether two matrices can be multiplied

Kind: static method of Matrix
Returns: boolean - Whether two matrices can be summed (using matrix multiplication)

| Param | Type | Description | | ----- | ------------------- | --------------- | | x | Matrix | Matrix to check | | y | Matrix | Matrix to check |

Matrix.multiply(x, y) ⇒ Matrix

Calculates the dot product of two matrices

Kind: static method of Matrix
Returns: Matrix - New matrix with the dot product

| Param | Type | Description | | ----- | ------------------- | ------------------ | | x | Matrix | Matrix to multiply | | y | Matrix | Matrix to multiply |

multiply~z : Matrix

New matrix with the dot product

Kind: inner constant of multiply

Matrix.invert(Matrix) ⇒ Matrix

Inverts a matrix

Kind: static method of Matrix
Returns: Matrix - Matrix inverse

| Param | Type | Description | | ------ | -------------- | ----------- | | Matrix | x | to invert |

Matrix~matrix : Matrix

Single or multi dimensional matrix

Kind: inner constant of Matrix

Matrix~innerproduct(x, y, i) ⇒ number

Calculates the inner product of two matrices

Kind: inner method of Matrix
Returns: number - Inner product of matrices

| Param | Type | Description | | ----- | ------------------- | ------------------------------ | | x | Matrix | Matrix to multiply | | y | Matrix | Matrix to multiply | | i | number | Column in matrix y to multiply |

Testing

matrix includes several unit tests. After cloning the matrix repo locally, run npm install in the project folder to install dependencies. Run npm test to execute the tests.