Skip to content

Commit bff7edc

Browse files
docs: update examples of array/base
PR-URL: #2021 Closes: #1546 --------- Co-authored-by: Philipp Burckhardt <[email protected]> Reviewed-by: Philipp Burckhardt <[email protected]>
1 parent 8e110d6 commit bff7edc

File tree

2 files changed

+45
-6
lines changed

2 files changed

+45
-6
lines changed

lib/node_modules/@stdlib/array/base/README.md

+20-4
Original file line numberDiff line numberDiff line change
@@ -234,15 +234,31 @@ The namespace exports the following:
234234

235235
## Examples
236236

237-
<!-- TODO: better examples -->
238-
239237
<!-- eslint no-undef: "error" -->
240238

241239
```javascript
242-
var objectKeys = require( '@stdlib/utils/keys' );
240+
var randu = require( '@stdlib/random/base/randu' );
243241
var ns = require( '@stdlib/array/base' );
244242

245-
console.log( objectKeys( ns ) );
243+
// Create a zero-filled array:
244+
var zeros = ns.zeros( 5 );
245+
// returns [ 0, 0, 0, 0, 0 ]
246+
247+
// Create an array filled with a specific value:
248+
var filled = ns.filled( 7, 4 );
249+
// returns [ 7, 7, 7, 7 ]
250+
251+
// Create a linearly spaced array:
252+
var linear = ns.linspace( 0, 1, 5 );
253+
// returns [ 0, 0.25, 0.5, 0.75, 1 ]
254+
255+
// Create a two-dimensional array:
256+
var arr2d = ns.ones2d( [ 2, 3 ] );
257+
// returns [ [ 1, 1, 1 ], [ 1, 1, 1 ] ]
258+
259+
// Map a function over a 2D array:
260+
var squared = ns.map2d( arr2d, [ 2, 3 ], randu );
261+
// e.g., returns [ [ ~0.123, ~0.789, ~0.456 ], [ ~0.321, ~0.654, ~0.987 ] ]
246262
```
247263

248264
</section>

lib/node_modules/@stdlib/array/base/examples/index.js

+25-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,30 @@
1818

1919
'use strict';
2020

21-
var objectKeys = require( '@stdlib/utils/keys' );
21+
var randu = require( '@stdlib/random/base/randu' );
2222
var ns = require( './../lib' );
2323

24-
console.log( objectKeys( ns ) );
24+
// Create a zero-filled array:
25+
var zeros = ns.zeros( 5 );
26+
console.log( zeros );
27+
// => [ 0, 0, 0, 0, 0 ]
28+
29+
// Create an array filled with a specific value:
30+
var filled = ns.filled( 7, 4 );
31+
console.log( filled );
32+
// => [ 7, 7, 7, 7 ]
33+
34+
// Create a linearly spaced array:
35+
var linear = ns.linspace( 0, 1, 5 );
36+
console.log( linear );
37+
// => [ 0, 0.25, 0.5, 0.75, 1 ]
38+
39+
// Create a two-dimensional array:
40+
var arr2d = ns.ones2d( [ 2, 3 ] );
41+
console.log( arr2d );
42+
// => [ [ 1, 1, 1 ], [ 1, 1, 1 ] ]
43+
44+
// Map a function over a 2D array:
45+
var squared = ns.map2d( arr2d, [ 2, 3 ], randu );
46+
console.log( squared );
47+
// e.g., => [ [ ~0.123, ~0.789, ~0.456 ], [ ~0.321, ~0.654, ~0.987 ] ]

0 commit comments

Comments
 (0)