You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
> Return the first element in the [ndarray][@stdlib/ndarray/ctor]that passes a test implemented by a predicate function.
23
+
> Return a new [ndarray][@stdlib/ndarray/ctor]containing the first elements which pass a test implemented by a predicate function along one or more [ndarray][@stdlib/ndarray/ctor] dimensions.
24
24
25
25
<sectionclass="intro">
26
26
@@ -32,128 +32,235 @@ limitations under the License.
Return the first element in the [ndarray][@stdlib/ndarray/ctor]that passes a test implemented by a predicate function.
45
+
Returns a new [ndarray][@stdlib/ndarray/ctor]containing the first elements which pass a test implemented by a predicate function along one or more [ndarray][@stdlib/ndarray/ctor] dimensions.
-**sentinelValue**: the value to return when no element passes the test. May be either a scalar value or a zero-dimensional [ndarray][@stdlib/ndarray/ctor].
72
72
-**options**: function options _(optional)_.
73
73
-**predicate**: predicate function.
74
74
-**thisArg**: predicate function execution context _(optional)_.
75
75
76
76
The function accepts the following options:
77
77
78
-
-**order**: index iteration order. By default, the function iterates over elements according to the [layout order][@stdlib/ndarray/orders] of the provided [ndarray][@stdlib/ndarray/ctor]. Accordingly, for row-major input [ndarrays][@stdlib/ndarray/ctor], the last dimension indices increment fastest. For column-major input [ndarrays][@stdlib/ndarray/ctor], the first dimension indices increment fastest. To override the inferred order and ensure that indices increment in a specific manner, regardless of the input [ndarray][@stdlib/ndarray/ctor]'s layout order, explicitly set the iteration order. Note, however, that iterating according to an order which does not match that of the input [ndarray][@stdlib/ndarray/ctor] may, in some circumstances, result in performance degradation due to cache misses. Must be either `'row-major'` or `'column-major'`.
78
+
-**dims**: list of dimensions over which to perform a reduction.
79
+
-**keepdims**: boolean indicating whether the reduced dimensions should be included in the returned [ndarray][@stdlib/ndarray/ctor] as singleton dimensions. Default: `false`.
79
80
80
-
By default, the output element's [data type][@stdlib/ndarray/dtypes] is inferred from the input [ndarray][@stdlib/ndarray/ctor].
81
-
82
-
<!-- eslint-disable max-len -->
81
+
By default, the function performs reduction over all all elements in a provided [ndarray][@stdlib/ndarray/ctor]. To reduce specific dimensions, set the `dims` option.
By default, the function returns an [ndarray][@stdlib/ndarray/ctor] having a shape matching only the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor] (i.e., the reduced dimensions are dropped). To include the reduced dimensions as singleton dimensions in the output [ndarray][@stdlib/ndarray/ctor], set the `keepdims` option to `true`.
108
+
109
+
```javascript
110
+
var array =require( '@stdlib/ndarray/array' );
111
+
var ndarray2array =require( '@stdlib/ndarray/to-array' );
-**arr**: the input [ndarray][@stdlib/ndarray/ctor].
190
+
Finds the first elements which pass a test implemented by a predicate function along one or more [ndarray][@stdlib/ndarray/ctor] dimensions and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor].
-**sentinelValue**: the value to return when no element passes the test. May be either a scalar value or a zero-dimensional [ndarray][@stdlib/ndarray/ctor].
225
+
-**options**: function options _(optional)_.
226
+
-**predicate**: predicate function.
227
+
-**thisArg**: predicate function execution context _(optional)_.
228
+
229
+
The function accepts the following `options`:
230
+
231
+
-**dims**: list of dimensions over which to perform a reduction.
232
+
233
+
```javascript
234
+
var array =require( '@stdlib/ndarray/array' );
235
+
var empty =require( '@stdlib/ndarray/empty' );
236
+
var ndarray2array =require( '@stdlib/ndarray/to-array' );
@@ -163,7 +270,18 @@ The `predicate` function is provided the following arguments:
163
270
164
271
## Notes
165
272
166
-
- The function returns **NaN** if no element in ndarray passes test implemented by the predicate function.
273
+
- By default, when no `sentinelValue` is provided, the function returns a default sentinel value based on the input [ndarray][@stdlib/ndarray/ctor][data-type][@stdlib/ndarray/dtypes]:
274
+
275
+
- floating-point numbers: `NaN`.
276
+
- complex numbers: `NaN + NaNj`.
277
+
- integers: maximum value.
278
+
- boolean: `false`.
279
+
280
+
- The `predicate` function is provided the following arguments:
281
+
282
+
-**value**: current array element.
283
+
-**indices**: current array element indices.
284
+
-**arr**: the input [ndarray][@stdlib/ndarray/ctor].
167
285
168
286
</section>
169
287
@@ -176,23 +294,20 @@ The `predicate` function is provided the following arguments:
176
294
<!-- eslint no-undef: "error" -->
177
295
178
296
```javascript
179
-
var discreteUniform =require( '@stdlib/random/array/discrete-uniform' );
297
+
var discreteUniform =require( '@stdlib/random/base/discrete-uniform' ).factory;
298
+
var isEven =require( '@stdlib/assert/is-even' ).isPrimitive;
180
299
var ndarray2array =require( '@stdlib/ndarray/to-array' );
181
-
var naryFunction =require( '@stdlib/utils/nary-function' );
182
-
var array =require( '@stdlib/ndarray/array' );
183
-
var isPositive =require( '@stdlib/assert/is-positive-number' ).isPrimitive;
184
-
var findElement =require( '@stdlib/ndarray/find' );
300
+
var fillBy =require( '@stdlib/ndarray/fill-by' );
301
+
var zeros =require( '@stdlib/ndarray/zeros' );
302
+
var find =require( '@stdlib/ndarray/find' );
185
303
186
-
var buffer =discreteUniform( 10, -100, 100, {
187
-
'dtype':'generic'
188
-
});
189
-
var x =array( buffer, {
190
-
'shape': [ 5, 2 ],
191
-
'dtype':'generic'
304
+
var x =zeros( [ 2, 4, 5 ], {
305
+
'dtype':'float64'
192
306
});
307
+
x =fillBy( x, discreteUniform( 0, 10 ) );
193
308
console.log( ndarray2array( x ) );
194
309
195
-
var y =findElement( x, naryFunction( isPositive, 1 ) );
0 commit comments