|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2023 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# numel |
| 22 | + |
| 23 | +> Return the number of elements in an [ndarray][@stdlib/ndarray/ctor]. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var numel = require( '@stdlib/ndarray/numel' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### numel( x ) |
| 44 | + |
| 45 | +Returns number of elements in an [ndarray][@stdlib/ndarray/ctor]. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var zeros = require( '@stdlib/ndarray/zeros' ); |
| 49 | + |
| 50 | +var x = zeros( [ 3, 2, 3 ] ); |
| 51 | +// returns <ndarray> |
| 52 | + |
| 53 | +var n = numel( x ); |
| 54 | +// returns 18 |
| 55 | +``` |
| 56 | + |
| 57 | +</section> |
| 58 | + |
| 59 | +<!-- /.usage --> |
| 60 | + |
| 61 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 62 | + |
| 63 | +<section class="notes"> |
| 64 | + |
| 65 | +</section> |
| 66 | + |
| 67 | +<!-- /.notes --> |
| 68 | + |
| 69 | +<!-- Package usage examples. --> |
| 70 | + |
| 71 | +<section class="examples"> |
| 72 | + |
| 73 | +## Examples |
| 74 | + |
| 75 | +<!-- eslint no-undef: "error" --> |
| 76 | + |
| 77 | +<!-- eslint-disable new-cap --> |
| 78 | + |
| 79 | +```javascript |
| 80 | +var zeros = require( '@stdlib/ndarray/zeros' ); |
| 81 | +var slice = require( '@stdlib/ndarray/slice' ); |
| 82 | +var E = require( '@stdlib/slice/multi' ); |
| 83 | +var S = require( '@stdlib/slice/ctor' ); |
| 84 | +var numel = require( '@stdlib/ndarray/numel' ); |
| 85 | + |
| 86 | +// Create an array: |
| 87 | +var x = zeros( [ 10, 10, 10, 10 ] ); |
| 88 | +// returns <ndarray> |
| 89 | + |
| 90 | +// Define some slices: |
| 91 | +var slices = [ |
| 92 | + // :,:,:,: |
| 93 | + E( null, null, null, null ), |
| 94 | + |
| 95 | + // 5:10,:,2:4,::-1 |
| 96 | + E( S( 5, 10 ), null, S( 2, 4 ), S( null, null, -1 ) ), |
| 97 | + |
| 98 | + // :,:,2,: |
| 99 | + E( null, null, 2, null ), |
| 100 | + |
| 101 | + // 1,2,3,4 |
| 102 | + E( 1, 2, 3, 4 ), |
| 103 | + |
| 104 | + // :,:,::2,4::2 |
| 105 | + E( null, null, S( null, null, 2 ), S( 4, null, 2 ) ) |
| 106 | +]; |
| 107 | + |
| 108 | +// Determine the number of elements in each slice... |
| 109 | +var s; |
| 110 | +var i; |
| 111 | +for ( i = 0; i < slices.length; i++ ) { |
| 112 | + s = slice( x, slices[ i ] ); |
| 113 | + console.log( '%s => %d elements', s.shape.join( 'x' ), numel( s ) ); |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +</section> |
| 118 | + |
| 119 | +<!-- /.examples --> |
| 120 | + |
| 121 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 122 | + |
| 123 | +<section class="references"> |
| 124 | + |
| 125 | +</section> |
| 126 | + |
| 127 | +<!-- /.references --> |
| 128 | + |
| 129 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 130 | + |
| 131 | +<section class="related"> |
| 132 | + |
| 133 | +</section> |
| 134 | + |
| 135 | +<!-- /.related --> |
| 136 | + |
| 137 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 138 | + |
| 139 | +<section class="links"> |
| 140 | + |
| 141 | +[@stdlib/ndarray/ctor]: https://github.com/stdlib-js/stdlib |
| 142 | + |
| 143 | +</section> |
| 144 | + |
| 145 | +<!-- /.links --> |
0 commit comments