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

mtrx

v0.1.6

Published

A simple Array-like matrix calculation library.

Readme

default class Mtrx is extends Array.

Installation

    $ npm install mtrx

Properties

  • Mtrx.rows
  • Mtrx.cols
  • Mtrx.rank
  • Mtrx.det

Methods

  • Mtrx.zeros()
  • Mtrx.ones()
  • Mtrx.eye()
  • Mtrx.rand()
  • Mtrx.like()
  • Mtrx.diag()
  • Mtrx.clone()
  • Mtrx.isMtrx()
  • Mtrx.isMtrxLike()
  • Mtrx.isDiag()
  • Mtrx.isSingular()
  • Mtrx.isSameShape()
  • Mtrx.equal()
  • Mtrx.equalAll()
  • Mtrx.equalAny()
  • Mtrx.prototype.get()
  • Mtrx.prototype.set()
  • Mtrx.prototype.changeRows()
  • Mtrx.prototype.changeCols()
  • Mtrx.prototype.resetLike()
  • Mtrx.prototype.cof()
  • Mtrx.prototype.T()
  • Mtrx.prototype.compan()
  • Mtrx.prototype.inv()
  • Mtrx.prototype.LUP()
  • Mtrx.prototype.mapMtrx()
  • Mtrx.prototype.everyMtrx()
  • Mtrx.prototype.someMtrx()
  • Mtrx.prototype.reduceMtrx()
  • Mtrx.prototype.rightMul()
  • Mtrx.prototype.leftMul()
  • Mtrx.prototype.rightDiv()
  • Mtrx.prototype.leftDiv()

Usage

    const Mtrx = require('mtrx');

creation

It is really easy to create a matrix object what you want.

    // No arguments, create a 1x1 random(0 ~ 1) matrix
    new Mtrx()
    // -> Mtrx [ [ 0.7173410249746024 ] ]
    
    new Mtrx(2)
    // -> Mtrx [
    //  [ 0.9028933497295337, 0.18980748816858917 ],
    //  [ 0.10859200880292263, 0.560035422729191 ] ]
    
    new Mtrx(2, 3)
    // -> Mtrx [
    //  [ 0.6974184450003136, 0.6402339494410889, 0.4553998131618524 ],
    //  [ 0.38759912033793165, 0.8904429716538196, 0.7449091649551736 ] ]
    
    new Mtrx(3, 4, 9)
    // -> Mtrx [ [ 9, 9, 9, 9 ], [ 9, 9, 9, 9 ], [ 9, 9, 9, 9 ] ]
    
    // Get numbers array, create a diag matrix
    new Mtrx([2, 4, 6])
    // -> Mtrx [ [ 2, 0, 0 ], [ 0, 4, 0 ], [ 0, 0, 6 ] ]
    
    // Get a 2-order numbers array, create a matrix like the array
    new Mtrx([[1, 2, 3], [4, 5, 6]])
    // -> Mtrx [ [ 1, 2, 3 ], [ 4, 5, 6 ] ]
    
    // Get a function expression, create a matrix by the expression
    new Mtrx(2, 3, (i, j) => i + j)
    // -> Mtrx [ [ 0, 1, 2 ], [ 1, 2, 3 ] ]

operation

Mtrx object is a Array-like object. So, you can operat it just like to operat a 2-order Array.

    const m = new Mtrx(2, 3, 0)
    // -> Mtrx [ [ 0, 0, 0 ], [ 0, 0, 0 ] ]
    
    m[1][1]     // or     m.get(1, 1)
    // -> 0
    
    m[0][1] = 1     //or     m.set(0, 1, 1)
    // -> Mtrx [ [ 0, 1, 0 ], [ 0, 0, 0 ] ]

properties

    const m = new Mtrx(2, 3, (i, j) => (i === j) ? 1 : 0)
    // -> Mtrx [ [ 1, 0, 0 ], [ 0, 1, 0 ] ]
    const n = new Mtrx([
      [1, 2, 0],
      [3, 4, 4],
      [5, 6, 3]
    ])
    
    m.rows  // -> 2
    m.cols  // -> 3
    
    n.det  // -> 10
    m.det  // -> NaN
    // If the Mtrx object's rows and cols was not equal, det would be NaN
    
    m.rank  // -> 2     
    m[0][0] = 0
    // -> Mtrx [ [ 0, 0, 0 ], [ 0, 1, 0 ] ]
    m.rank  // -> 1

static function

all the static functions is Immutable.

    Mtrx.zeros(3, 3)
    // -> Mtrx [ [ 0, 0, 0 ], [ 0, 0, 0 ], [ 0, 0, 0 ] ]
    
    Mtrx.ones(3, 4)
    // -> Mtrx [ [ 1, 1, 1, 1 ], [ 1, 1, 1, 1 ], [ 1, 1, 1, 1 ] ]
    
    Mtrx.eye(3)
    // -> Mtrx [ [ 1, 0, 0 ], [ 0, 1, 0 ], [ 0, 0, 1] ]
    
    Mtrx.diag([2, 4, 6])
    // -> Mtrx [ [ 2, 0, 0 ], [ 0, 4, 0 ], [ 0, 0, 6 ] ]

    const n = [[0, 1, 2], [1, 2, 3]]
    const m = new Mtrx(n)
    // -> Mtrx [ [ 0, 1, 2 ], [ 1, 2, 3 ] ]
    
    Mtrx.isMtrx(n)     // -> false
    Mtrx.isMtrx(m)     // -> true
    
    Mtrx.isMtrxLike(n)     // -> true
    Mtrx.isDiag(m)     // -> false
    Mtrx.isSameShape(m, n)     // -> true

    const m = new Mtrx([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    const n = new Mtrx([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    
    Mtrx.add(m, n)
    // -> Mtrx [ [ 2, 2, 3 ], [ 4, 6, 6 ], [ 7, 8, 10 ] ]
    
    Mtrx.mul(m, 3)
    // -> Mtrx [ [ 3, 0, 0 ], [ 0, 3, 0 ], [ 0, 0, 3 ] ]
    
    Mtrx.mul(m, n)
    // -> Mtrx [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]
    
    Mtrx.div(n, m)
    // -> Mtrx [ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ] ]

methods

Following functions will always return a new Mtrx object.

    const m = new Mtrx([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
    const n = new Mtrx([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
    
    m.add(n)   // like Mtrx.add(m, n)
    
    m.leftMul(n)   // like Mtrx.mul(m, n)
    m.rightMul(n)   // like Mtrx.mul(n, m)
    
    n.cof(1, 1)
    // -> Mtrx [ [ 1, 3 ], [ 7, 9 ] ]
    
    // a powerful function
    m.mapMtrx((i, j, n) => i + j + n);
    // -> Mtrx [ [ 1, 1, 2 ], [ 1, 3, 3 ], [ 2, 3, 5 ] ]

    const m = new Mtrx(2, 3, (i, j) => (i === j) ? 1 : 0)
    // -> Mtrx [ [ 1, 0, 0 ], [ 0, 1, 0 ] ]
    const n = new Mtrx([
      [1, 2, 0],
      [3, 4, 4],
      [5, 6, 3]
    ])
    
    n.T()
    
    n.LUP()
    // -> { L: Mtrx [ [ 1, 0, 0 ], [ 0.2, 1, 0 ], [ 0.6, 0.5, 1 ] ],
    //      U: Mtrx [ [ 5, 6, 3 ], [ 0, 0.8, -0.6 ], [ 0, 0, 2.5 ] ],
    //      P: Mtrx [ [ 0, 0, 1 ], [ 1, 0, 0 ], [ 0, 1, 0 ] ] }
    n.LUP().L
    // -> Mtrx [ [ 1, 0, 0 ], [ 0.2, 1, 0 ], [ 0.6, 0.5, 1 ] ]
    
    n.inv()
    // -> Mtrx [ [ -1.2, -0.6, 0.8 ], [ 1.1, 0.3, -0.4 ], [ -0.2, 0.4, -0.2 ] ]
    
    // If there is no corresponding matrix, you would get a Error.
    m.LUP()
    m.inv()
    m.compan()
    // -> Error: ...