Code Monkey home page Code Monkey logo

hedgehog-matrix's Introduction

Hedgehog-matrix

Hedgehog-matrix is a library for JavaScript with sweet operator-overload syntax supported by Babel.

Setup

To use in Node.js, please

npm install Hedgehog-matrix

Also install Babel and babel-plugin-overload

Quick start

Initialize a matrix

// Import matrix class from library
import {Mat} from 'hedgehog-matrix';        

// Initialize a new matrix
//  1  ,  2
//  3  ,  4
var a = new Mat([[1,2], [3,4]]);

Clone matrix A to B

var b = a.clone();

Matrix manipulation:

// c = a + b*2 + 10
var c = a+b*2+10;

// d = ( a * b - a ) * 0.5
var d = (a*b-a)*0.5

// x = a'*a
var x = a.T() * a

Matrix utilities

// initialize a matrix e as: 
// 1,2,3
// 4,5,6
// 7,8,9
var e = new Mat()     // initialize new empty matrix
     .range(1, 10)    // initialize as a 9*1 matrix with all elements [1,10)
     .reshape(3 ,3);  // reshape the matrix into a 3*3 matrix



//zeros
var zeros = new Mat().zeros(10,10);

//ones
var ones = new Mat().ones(10,10);

//identity matrix
var diag_mat = new Mat().identity(10);

//random matrix
var random_mat = new Mat().random(10,10);

Compare operator overload

// compare a * a with another matrix [[7,10], [15,22]] using operator "=="
if ( a * a == new Mat([
    [7, 10],
    [15,22]]  ) )
{
    console.log("Yay! Operator == works !");
}
else
{
    console.log("Operator == doens't work");
}

Matrix / CSV / JSON convertor

var x = csv2mat(
    '1,2,3
     4,5,6
     7,8,9');

var y = mat2csv(x);

var json_x = mat2json(x);
var x_from_json = json2mat(json_x);

hedgehog-matrix's People

Contributors

lidangzzz avatar xrw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.