Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork0
Create an iterator which iterates over each subarray in a stack of subarrays.
License
stdlib-js/ndarray-iter-subarrays
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
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!
Create an iterator which iterates over each subarray in a stack of subarrays.
importnditerSubarraysfrom'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-subarrays@deno/mod.js';
Returns an iterator which iterates over each subarray in a stack of subarrays.
importarrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@deno/mod.js';importndarray2arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@deno/mod.js';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 returned
ndarrayviews should be read-only. In order to return writablendarrayviews, the inputndarraymust be writable. If the inputndarrayis read-only, setting this option tofalseraises an exception. Default:true.
By default, the iterator returnsndarray views which areread-only. To return writableviews, set thereadonly option tofalse.
importarrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@deno/mod.js';importndarray2arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@deno/mod.js';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 a
valueproperty and adoneproperty having abooleanvalue indicating whether theiterator is finished. - return: function which closes aniterator and returns a single (optional) argument in aniterator protocol-compliant object.
- The input
ndarraymust have at leastndims+1dimensions. - If an environment supports
Symbol.iterator, the returned iterator is iterable. - A returned iterator doesnot copy a provided
ndarray. To ensure iterable reproducibility, copy the inputndarraybefore creating an iterator. Otherwise, any changes to the contents of inputndarraywill be reflected in the returned iterator. - In environments supporting
Symbol.iterator, the functionexplicitly doesnot invoke an ndarray's@@iteratormethod, regardless of whether this method is defined.
importarrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-array@deno/mod.js';importzeroTofrom'https://cdn.jsdelivr.net/gh/stdlib-js/array-base-zero-to@deno/mod.js';importndarray2arrayfrom'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-to-array@deno/mod.js';importnditerSubarraysfrom'https://cdn.jsdelivr.net/gh/stdlib-js/ndarray-iter-subarrays@deno/mod.js';// 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));}
@stdlib/ndarray-iter/columns:create an iterator which iterates over each column in a matrix (or stack of matrices).@stdlib/ndarray-iter/matrices:create an iterator which iterates over each matrix in a stack of matrices.@stdlib/ndarray-iter/rows:create an iterator which iterates over each row in a matrix (or stack of matrices).@stdlib/ndarray-iter/stacks:create an iterator which iterates over each subarray in a stack of subarrays according to a list of specified stack dimensions.@stdlib/ndarray-slice:return a read-only view of an input ndarray.
This package is part ofstdlib, a standard library 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.
SeeLICENSE.
Copyright © 2016-2025. The StdlibAuthors.
About
Create an iterator which iterates over each subarray in a stack of subarrays.
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Sponsor this project
Uh oh!
There was an error while loading.Please reload this page.