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
Returns the first index of a specified search element along one or more [ndarray][@stdlib/ndarray/ctor]dimensions.
35
+
Returns the first index of a specified search element along an [ndarray][@stdlib/ndarray/ctor]dimension.
36
36
37
37
```javascript
38
38
var array =require( '@stdlib/ndarray/array' );
@@ -51,18 +51,18 @@ var idx = out.get();
51
51
52
52
The function has the following parameters:
53
53
54
-
-**x**: input [ndarray][@stdlib/ndarray/ctor].
55
-
- **searchElement**: element in an input [ndarray][@stdlib/ndarray/ctor] for which to find an index. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] same as the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided a scalar value, the value is cast to the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, the search element [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], the search element [ndarray][@stdlib/ndarray/ctor] must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor].
56
-
-**fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an `integer`or `generic`[data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor]containing the index from which to begin searching must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the index from which to begin searching is`0`.
54
+
-**x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension.
55
+
-**searchElement**: search element. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor]. If provided a scalar value, the value is cast to the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, the search element [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`.
56
+
-**fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic"[data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, a provided [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. If provided a negative integer, the index at which to begin searching along a dimension is determined by counting backward from the last element (where `-1` refers to the last element). Default:`0`.
57
57
-**options**: function options (_optional_).
58
58
59
59
The function accepts the following options:
60
60
61
-
-**dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be an integer or generic [data type][@stdlib/ndarray/dtypes].
62
-
-**dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor].
61
+
-**dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. Must be an integer index or generic [data type][@stdlib/ndarray/dtypes].
62
+
-**dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`.
63
63
-**keepdims**: boolean indicating whether the reduced dimensions should be included in the returned [ndarray][@stdlib/ndarray/ctor] as singleton dimensions. Default: `false`.
64
64
65
-
If the function is unable to find a search element, the function returns`-1`.
65
+
If the function is unable to find a search element along an [ndarray][@stdlib/ndarray/ctor], the corresponding element in the returned [ndarray][@stdlib/ndarray/ctor] is`-1`.
66
66
67
67
```javascript
68
68
var array =require( '@stdlib/ndarray/array' );
@@ -79,7 +79,7 @@ var idx = out.get();
79
79
// returns -1
80
80
```
81
81
82
-
By default, the function uses `0` as the index from which to begin searching. To begin searching from a different index, provide the`fromIndex` argument.
82
+
By default, the function begins searching from the first element along the reduction dimension. To begin searching from a different index, provide a`fromIndex` argument.
83
83
84
84
```javascript
85
85
var array =require( '@stdlib/ndarray/array' );
@@ -96,7 +96,7 @@ var idx = out.get();
96
96
// returns 4
97
97
```
98
98
99
-
By default, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor]. To perform the operation over specific dimensions, provide a `dims` option.
99
+
By default, the function performs the operation over elements in the last dimension. To perform the operation over a different dimension, provide a `dim` option.
100
100
101
101
```javascript
102
102
var ndarray2array =require( '@stdlib/ndarray/to-array' );
@@ -105,30 +105,27 @@ var array = require( '@stdlib/ndarray/array' );
105
105
var x =array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] );
106
106
107
107
var out =indexOf( x, -3.0, {
108
-
'dims':[ 0 ]
108
+
'dim':0
109
109
});
110
110
// returns <ndarray>
111
111
112
112
var idx =ndarray2array( out );
113
113
// returns [ 1, -1 ]
114
114
```
115
115
116
-
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`.
116
+
By default, the function excludes reduced dimensions from the output [ndarray][@stdlib/ndarray/ctor]. To include the reduced dimensions as singleton dimensions, set the `keepdims` option to `true`.
117
117
118
118
```javascript
119
119
var array =require( '@stdlib/ndarray/array' );
120
120
var ndarray2array =require( '@stdlib/ndarray/to-array' );
121
121
122
-
// Create an input ndarray:
123
122
var x =array( [ [ -1.0, 2.0 ], [ -3.0, 4.0 ] ] );
124
-
// returns <ndarray>
125
123
126
124
var opts = {
127
-
'dims':[ 0 ],
125
+
'dim':0,
128
126
'keepdims':true
129
127
};
130
128
131
-
// Find index:
132
129
var out =indexOf( x, -3.0, opts );
133
130
// returns <ndarray>
134
131
@@ -146,17 +143,17 @@ var array = require( '@stdlib/ndarray/array' );
Returns the first index of a specified search element along one or more [ndarray][@stdlib/ndarray/ctor]dimensions and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor].
156
+
Returns the first index of a specified search element along an [ndarray][@stdlib/ndarray/ctor]dimension and assigns results to a provided output [ndarray][@stdlib/ndarray/ctor].
160
157
161
158
```javascript
162
159
var array =require( '@stdlib/ndarray/array' );
@@ -179,15 +176,15 @@ var bool = ( out === y );
179
176
180
177
The method has the following parameters:
181
178
182
-
-**x**: input [ndarray][@stdlib/ndarray/ctor].
183
-
- **searchElement**: element in an input [ndarray][@stdlib/ndarray/ctor] for which to find an index. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having a [data type][@stdlib/ndarray/dtypes] same as the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided a scalar value, the value is cast to the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, the search element [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] initial value must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor].
184
-
-**fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an `integer`or `generic`[data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the complement of the shape defined by `options.dims`. For example, given the input shape `[2, 3, 4]` and `options.dims=[0]`, an [ndarray][@stdlib/ndarray/ctor]containing the index from which to begin searching must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. Similarly, when performing the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor], an [ndarray][@stdlib/ndarray/ctor] containing the index from which to begin searching must be a zero-dimensional [ndarray][@stdlib/ndarray/ctor]. By default, the index from which to begin searching is`0`.
185
-
-**out**: output [ndarray][@stdlib/ndarray/ctor]. Must have an `integer` or `generic`[data type][@stdlib/ndarray/dtypes].
179
+
-**x**: input [ndarray][@stdlib/ndarray/ctor]. Must have at least one dimension.
180
+
-**searchElement**: search element. May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor]. If provided a scalar value, the value is cast to the data type of the input [ndarray][@stdlib/ndarray/ctor]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, the search element [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`.
181
+
-**fromIndex**: index from which to begin searching (_optional_). May be either a scalar value or an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic"[data type][@stdlib/ndarray/dtypes]. If provided an [ndarray][@stdlib/ndarray/ctor], the value must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the non-reduced dimensions of the input [ndarray][@stdlib/ndarray/ctor]. For example, given the input shape `[2, 3, 4]` and `options.dim=0`, a provided [ndarray][@stdlib/ndarray/ctor] must have a shape which is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with the shape `[3, 4]`. If provided a negative integer, the index at which to begin searching along a dimension is determined by counting backward from the last element (where `-1` refers to the last element). Default:`0`.
182
+
-**out**: output [ndarray][@stdlib/ndarray/ctor].
186
183
-**options**: function options (_optional_).
187
184
188
185
The method accepts the following options:
189
186
190
-
-**dims**: list of dimensions over which to perform operation. If not provided, the function performs the operation over all elements in a provided input [ndarray][@stdlib/ndarray/ctor].
187
+
-**dim**: dimension over which to perform operation. If provided a negative integer, the dimension along which to perform the operation is determined by counting backward from the last dimension (where `-1` refers to the last dimension). Default: `-1`.
191
188
192
189
</section>
193
190
@@ -197,7 +194,8 @@ The method accepts the following options:
197
194
198
195
## Notes
199
196
200
-
- Both functions iterate over [ndarray][@stdlib/ndarray/ctor] elements according to the memory layout of the input [ndarray][@stdlib/ndarray/ctor]. Accordingly, performance degradation is possible when operating over multiple dimensions of a large non-contiguous multi-dimensional input [ndarray][@stdlib/ndarray/ctor]. In such scenarios, one may want to copy an input [ndarray][@stdlib/ndarray/ctor] to contiguous memory before searching for an index.
197
+
- Setting the `keepdims` option to `true` can be useful when wanting to ensure that the output [ndarray][@stdlib/ndarray/ctor] is [broadcast-compatible][@stdlib/ndarray/base/broadcast-shapes] with ndarrays having the same shape as the input [ndarray][@stdlib/ndarray/ctor].
198
+
- The output data type [policy][@stdlib/ndarray/output-dtype-policies] only applies to the main function and specifies that, by default, the function must return an [ndarray][@stdlib/ndarray/ctor] having an integer index or "generic" [data type][@stdlib/ndarray/dtypes]. For the `assign` method, the output [ndarray][@stdlib/ndarray/ctor] is allowed to have any supported output [data type][@stdlib/ndarray/dtypes].
0 commit comments