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
Copy file name to clipboardExpand all lines: lib/node_modules/@stdlib/ndarray/map/README.md
+90-26Lines changed: 90 additions & 26 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ limitations under the License.
20
20
21
21
# map
22
22
23
-
> Apply a callback function to elements in an input ndarray and assign results to elements in an output ndarray.
23
+
> Apply a callback function to elements in an input [ndarray][@stdlib/ndarray/ctor] and assign results to elements in a new output [ndarray][@stdlib/ndarray/ctor].
24
24
25
25
<sectionclass="intro">
26
26
@@ -36,56 +36,87 @@ limitations under the License.
36
36
var map =require( '@stdlib/ndarray/map' );
37
37
```
38
38
39
-
#### map( x, \[options, ]fcn\[, thisArg] )
39
+
#### map( x\[, options], fcn\[, thisArg] )
40
40
41
-
Applies a callback function to elements in an input ndarray and assigns results to elements in an output ndarray.
41
+
Applies a callback function to elements in an input [ndarray][@stdlib/ndarray/ctor] and assigns results to elements in a new output [ndarray][@stdlib/ndarray/ctor].
-**dtype**: output ndarray data type. Defaults to match the input ndarray if not specified.
78
+
-**dtype**: output ndarray [data type][@stdlib/ndarray/dtypes]. If not specified, the output ndarray [data type][@stdlib/ndarray/dtypes] is inferred from the input [ndarray][@stdlib/ndarray/ctor].
79
+
80
+
By default, the output ndarray [data type][@stdlib/ndarray/dtypes] is inferred from the input [ndarray][@stdlib/ndarray/ctor]. To return an ndarray with a different [data type][@stdlib/ndarray/dtypes], specify the `dtype` option.
The callback function is provided the following arguments:
85
116
86
117
-**values**: current array element.
87
118
-**indices**: current array element indices.
88
-
-**arr**: the input ndarray.
119
+
-**arr**: the input [ndarray][@stdlib/ndarray/ctor].
89
120
90
121
</section>
91
122
@@ -95,6 +126,35 @@ The callback function is provided the following arguments:
95
126
96
127
## Notes
97
128
129
+
- The function does **not** perform explicit casting (e.g., from a real-valued floating-point number to a complex floating-point number). Any such casting should be performed by a provided callback function.
var x =ndarray( 'float64', buffer, shape, strides, offset, 'row-major' );
149
+
// returns <ndarray>
150
+
151
+
var opts = {
152
+
'dtype':'complex128'
153
+
};
154
+
var y =map( x, opts, toComplex );
155
+
// returns <ndarray>
156
+
```
157
+
98
158
- For very high-dimensional ndarrays which are non-contiguous, one should consider copying the underlying data to contiguous memory before applying a callback function in order to achieve better performance.
99
159
100
160
</section>
@@ -110,7 +170,7 @@ The callback function is provided the following arguments:
110
170
```javascript
111
171
var discreteUniform = require( '@stdlib/random/array/discrete-uniform' );
112
172
var abs = require( '@stdlib/math/base/special/abs' );
113
-
var ndarray2array =require( '@stdlib/ndarray/base/to-array' );
173
+
var ndarray2array = require( '@stdlib/ndarray/to-array' );
114
174
var naryFunction = require( '@stdlib/utils/nary-function' );
115
175
var ndarray = require( '@stdlib/ndarray/ctor' );
116
176
var map = require( '@stdlib/ndarray/map' );
@@ -122,10 +182,10 @@ var shape = [ 5, 2 ];
122
182
var strides = [ 2, 1 ];
123
183
var offset =0;
124
184
var x =ndarray( 'generic', buffer, shape, strides, offset, 'row-major' );
0 commit comments