@stdlib/slice-base-reduced-dimensions
v0.2.2
Published
Return a list of reduced dimensions in an un-normalized multi-slice.
Downloads
24
Readme
reducedDimensions
Return a list of reduced dimensions in an un-normalized
MultiSlice
object.
In a multi-axis indexing expression (e.g., '1,:,2,:,0:10:1'), a non-reduced dimension corresponds to a dimension which is retained in the slice result. Only integer indexing expressions (e.g., only the first and third dimensions in '1,:,2,:,0:10:1') result in dimension reduction; slices always retain respective dimensions, even if a slice is empty or only selects a single element.
Installation
npm install @stdlib/slice-base-reduced-dimensions
Usage
var reducedDimensions = require( '@stdlib/slice-base-reduced-dimensions' );
reducedDimensions( slice )
Return a list of reduced dimensions in an un-normalized MultiSlice
object.
var MultiSlice = require( '@stdlib/slice-multi' );
var Slice = require( '@stdlib/slice-ctor' );
var s = new MultiSlice( 1, null, 2, void 0, new Slice( 0, 10, 1 ) );
// returns <MultiSlice>
var indices = reducedDimensions( s );
// returns [ 0, 2 ]
Examples
var S = require( '@stdlib/slice-ctor' );
var MultiSlice = require( '@stdlib/slice-multi' );
var reducedDimensions = require( '@stdlib/slice-base-reduced-dimensions' );
var s = new MultiSlice( null, S(), -1 );
var out = reducedDimensions( s );
console.log( '%s => [%s]', s.toString(), out.join( ',' ) );
s = new MultiSlice( null );
out = reducedDimensions( s );
console.log( '%s => [%s]', s.toString(), out.join( ',' ) );
s = new MultiSlice( S( -1, null, -1 ), 3 );
out = reducedDimensions( s );
console.log( '%s => [%s]', s.toString(), out.join( ',' ) );
s = new MultiSlice( 2, S( -10, -2, 2 ), 3, null );
out = reducedDimensions( s );
console.log( '%s => [%s]', s.toString(), out.join( ',' ) );
s = new MultiSlice( S( 1, 20, 2 ), S( null, null, -1 ) );
out = reducedDimensions( s );
console.log( '%s => [%s]', s.toString(), out.join( ',' ) );
Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2024. The Stdlib Authors.