extractDimension static method

List<NdArray> extractDimension({
  1. required int dimension,
  2. required List list,
})

Returns a list of each chunk at the given dimension.

The array [[[1, 2], [3, 4]], [[5, 6], [7, 8]]] creates a 2x2 cube.

extractDimension(dimension: 1);

The above example returns two 2x2 planes:

  • [[1, 2], [3, 4]]
  • [[5, 6], [7, 8]]

Note: The returned list is a list of NdArrays.

Implementation

static List<NdArray> extractDimension(
    {required int dimension, required List<dynamic> list}) {
  int numDimensions = countDimensions(list);

  if (dimension <= 0 || dimension > numDimensions) {
    throw ArgumentError('dimension must be between 0 and $numDimensions\n'
        'Actual: $dimension');
  }

  return _extractDimension(dimension, list, 1);
}