1.0.0 • Published 8 years ago
ndarray-vector-fill v1.0.0
ndarray-vector-fill
Fill an ndarray with component-wise vectors
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 initializedfunc
is a function ofn - 1
arguments that receives the corresponding indices of the firstn - 1
dimensions ofarray
. It should return an array with length matching the last dimension ofarray
.
Returns An initialized array
See Also
License
© 2016 Ricky Reusser. MIT License.
1.0.0
8 years ago