NumDart

Arrays

Array, Array2d and ArrayComplex, element-wise math and evenly spaced samples.

Like numpy.ndarray, numpy.linspace, numpy.arange

SciDart has three containers:

All of them are real Dart lists, so map, where, length and for loops work as usual.

Element-wise operations

+, -, * and / between two arrays of the same length work element by element. Operations with a scalar have their own functions, such as arrayMultiplyToScalar and arrayAddToScalar. Math functions follow the same naming: arraySin, arrayCos, arrayLog, arraySqrt, arrayPow.

Arrays and element-wise mathCreate an Array, combine arrays element by element and reduce them.
import 'package:scidart/numdart.dart';

void main() {
  var a = Array([1, 2, 3, 4]);
  var b = Array([10, 20, 30, 40]);

  print((a + b).toList()); // element-wise sum
  print((a * b).toList()); // element-wise product
  print(arrayMultiplyToScalar(a, 0.5).toList());
  print(arrayCumSum(a).toList());

  print('sum: ${arraySum(a)}, max: ${arrayMax(b)}, argmax: ${arrayArgMax(b)}');
}
Output
[11.0, 22.0, 33.0, 44.0]
[10.0, 40.0, 90.0, 160.0]
[0.5, 1.0, 1.5, 2.0]
[1.0, 3.0, 6.0, 10.0]
sum: 10.0, max: 40.0, argmax: 3

Reductions return a double or an index: arraySum, arrayMax, arrayMin, arrayArgMax, arrayNorm. arrayCumSum and arrayDiff return a new array.

Creating arrays

Ranges, linspace and filled arraysBuild evenly spaced samples like numpy.arange (createArrayRange) and numpy.linspace.
import 'package:scidart/numdart.dart';

void main() {
  print(createArrayRange(start: 0, stop: 10, step: 2).toList());
  print(linspace(0, 1, num: 5).toList());
  print(linspace(0, 1, num: 4, endpoint: false).toList());
  print(ones(3).toList());
  print(zeros(3).toList());
  print(Array2d.fixed(2, 3, initialValue: 7).map((r) => r.toList()).toList());
}
Output
[0.0, 2.0, 4.0, 6.0, 8.0]
[0.0, 0.25, 0.5, 0.75, 1.0]
[0.0, 0.25, 0.5, 0.75]
[1.0, 1.0, 1.0]
[0.0, 0.0, 0.0]
[[7.0, 7.0, 7.0], [7.0, 7.0, 7.0]]
  • linspace returns num samples between start and stop, including stop unless endpoint is false.
  • createArrayRange works like numpy.arange, with integer steps.
  • ones, zeros, Array.fixed and Array2d.fixed create filled arrays. logSpace gives samples evenly spaced on a log scale.

Copying

Arrays are mutable lists. Use Array.fromArray (or copy()) when a function must not change the caller's data.

Edit this guide on GitHub