Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Create an iterator which iterates over each subarray in a stack of subarrays.

License

NotificationsYou must be signed in to change notification settings

stdlib-js/ndarray-iter-subarrays

About stdlib...

We believe in a future in which the web is a preferred environment for numerical computation. To help realize this future, we've built stdlib. stdlib is a standard library, with an emphasis on numerical and scientific computation, written in JavaScript (and C) for execution in browsers and in Node.js.

The library is fully decomposable, being architected in such a way that you can swap out and mix and match APIs and functionality to cater to your exact preferences and use cases.

When you use stdlib, you can be absolutely certain that you are using the most thorough, rigorous, well-written, studied, documented, tested, measured, and high-quality code out there.

To join us in bringing numerical computing to the web, get started by checking us out onGitHub, and please considerfinancially supporting stdlib. We greatly appreciate your continued support!

nditerSubarrays

NPM versionBuild StatusCoverage Status

Create an iterator which iterates over each subarray in a stack of subarrays.

Installation

npm install @stdlib/ndarray-iter-subarrays

Alternatively,

  • To load the package in a website via ascript tag without installation and bundlers, use theES Module available on theesm branch (seeREADME).
  • If you are using Deno, visit thedeno branch (seeREADME for usage intructions).
  • For use in Observable, or in browser/node environments, use theUniversal Module Definition (UMD) build available on theumd branch (seeREADME).

Thebranches.md file summarizes the available branches and displays a diagram illustrating their relationships.

To view installation and usage instructions specific to each branch build, be sure to explicitly navigate to the respective README files on each branch, as linked to above.

Usage

varnditerSubarrays=require('@stdlib/ndarray-iter-subarrays');

nditerSubarrays( x, ndims[, options] )

Returns an iterator which iterates over each subarray in a stack of subarrays.

vararray=require('@stdlib/ndarray-array');varndarray2array=require('@stdlib/ndarray-to-array');varx=array([[[1,2],[3,4]],[[5,6],[7,8]]]);// returns <ndarray>variter=nditerSubarrays(x,2);varv=iter.next().value;// returns <ndarray>vararr=ndarray2array(v);// returns [ [ 1, 2 ], [ 3, 4 ] ]v=iter.next().value;// returns <ndarray>arr=ndarray2array(v);// returns [ [ 5, 6 ], [ 7, 8 ] ]// ...

The function accepts the followingoptions:

  • readonly: boolean indicating whether returnedndarray views should be read-only. In order to return writablendarray views, the inputndarray must be writable. If the inputndarray is read-only, setting this option tofalse raises an exception. Default:true.

By default, the iterator returnsndarray views which areread-only. To return writableviews, set thereadonly option tofalse.

vararray=require('@stdlib/ndarray-array');varndarray2array=require('@stdlib/ndarray-to-array');varx=array([[[1,2],[3,4]],[[5,6],[7,8]]]);// returns <ndarray>variter=nditerSubarrays(x,2,{'readonly':false});varv=iter.next().value;// returns <ndarray>vararr=ndarray2array(v);// returns [ [ 1, 2 ], [ 3, 4 ] ]v.set(0,0,10);arr=ndarray2array(v);// returns [ [ 10, 2 ], [ 3, 4 ] ]

The returnediterator protocol-compliant object has the following properties:

  • next: function which returns aniterator protocol-compliant object containing the next iterated value (if one exists) assigned to avalue property and adone property having aboolean value indicating whether theiterator is finished.
  • return: function which closes aniterator and returns a single (optional) argument in aniterator protocol-compliant object.

Notes

  • The inputndarray must have at leastndims+1 dimensions.
  • If an environment supportsSymbol.iterator, the returned iterator is iterable.
  • A returned iterator doesnot copy a providedndarray. To ensure iterable reproducibility, copy the inputndarraybefore creating an iterator. Otherwise, any changes to the contents of inputndarray will be reflected in the returned iterator.
  • In environments supportingSymbol.iterator, the functionexplicitly doesnot invoke an ndarray's@@iterator method, regardless of whether this method is defined.

Examples

vararray=require('@stdlib/ndarray-array');varzeroTo=require('@stdlib/array-base-zero-to');varndarray2array=require('@stdlib/ndarray-to-array');varnditerSubarrays=require('@stdlib/ndarray-iter-subarrays');// Define an input array:varx=array(zeroTo(27),{'shape':[3,3,3]});// Create an iterator for iterating over matrices:varit=nditerSubarrays(x,2);// Perform manual iteration...varv;while(true){v=it.next();if(v.done){break;}console.log(ndarray2array(v.value));}

See Also


Notice

This package is part ofstdlib, 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 developstdlib, see the main projectrepository.

Community

Chat


License

SeeLICENSE.

Copyright

Copyright © 2016-2025. The StdlibAuthors.

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp