Skip to content

nickmcintyre/numero

main
Switch branches/tags
Code

número

número

A friendly and intuitive math library for p5.js

All Contributors

Build Status

This addon library for p5.js turns the "software sketchbook" into a beginner-friendly environment for technical computing. It provides the following features:

  • A tensor object similar to NumPy arrays
  • A computer algebra system similar to SymPy (in progress)
  • A grammar of graphics similar to ggplot2 (in progress)
  • A grammar of data manipulation similar to dplyr
  • A machine learning API similar to scikit-learn (coming soon!)
  • A drawing turtle

The library is written in TypeScript and uses Day.js, Math.js, TensorFlow.js, and tidy.js under the hood. It bundles p5.tidy, TurtleGFX, and wildflower.

Usage

Plots

View the plotting example.

let iris;
let plot;

function preload() {
  iris = loadTable('iris.csv', 'csv', 'header');
}

function setup() {
  createCanvas(400, 400);

  iris.inferTypes();
  plot = createPlot(iris);

  noLoop();
}

function draw() {
  plot.title('Iris sepals');
  plot.xlabel('Width (cm)');
  plot.ylabel('Height (cm)');
  plot.point({
    x: 'SepalWidth',
    y: 'SepalLength',
  });
  plot.render();
}

Data Wrangling

View the Mauna Loa example.

let data;

function preload() {
  data = loadTable('co2.csv', 'csv', 'header');
}

function setup() {
  noCanvas()
  const results = tidy(
    data,
    filter((d) => d.mean > 400),
  );
  tidy(results, debug('Observations greater than 400ppm CO2'));
}

Tensors

View the matrix-vector example.

const a = createTensor([[1, 2], [3, 4]]);
const x = createTensor([5, 6]);
const b = a.dot(x);

b.print();

Demo

The fluid simulation below was created using a 2-dimensional lattice Boltzmann method.

A fluid simulation

Contributing

See CONTRIBUTING.

Contributors

Thanks goes to these wonderful people (emoji key):

Ashneel Das
Ashneel Das

💻 ⚠️

This project follows the all-contributors specification. Contributions of any kind welcome!