ndarray-vector-fill

1.0.0 • Public • Published

ndarray-vector-fill

Fill an ndarray with component-wise vectors

Build Status npm version Dependency Status Semistandard Style

Introduction

This module is very similar to ndarray-fill, except it fills an ndarray with vectors. This is useful when you have a function that computes, for example, all three components of a vector at the same time. Using ndarray-fill, you'd have to compute the function three times over and throw out most of the results.

Installation

$ npm i ndarray-vector-fill

Example

var fill = require('ndarray-vector-fill');
var pool = require('ndarray-scratch');
var show = require('ndarray-show');
 
var A = fill(pool.zeros([3, 3, 2], function (i, j) {
  return [i, 5 + j];
});
 
console.log(show(A));
// => 
//   0.000    5.000
//   0.000    6.000
//   0.000    7.000
//
//   1.000    5.000
//   1.000    6.000
//   1.000    7.000
//
//   2.000    5.000
//   2.000    6.000
//   2.000    7.000

Usage

require('ndarray-vector-fill')(array, func)

Iterates over the first n - 1 dimensions of array, filling the remaining dimensions with the components of func.

  • array is an ndarray which will be initialized
  • func is a function of n - 1 arguments that receives the corresponding indices of the first n - 1 dimensions of array. It should return an array with length matching the last dimension of array.

Returns An initialized array

See Also

License

© 2016 Ricky Reusser. MIT License.

Readme

Keywords

none

Package Sidebar

Install

npm i ndarray-vector-fill

Weekly Downloads

1

Version

1.0.0

License

MIT

Last publish

Collaborators

  • rreusser