|
| 1 | + |
| 2 | +{{alias}}( x, y, fcn[, thisArg] ) |
| 3 | + Applies a function to elements in two input arrays and assigns the results |
| 4 | + to a new array. |
| 5 | + |
| 6 | + The applied function is provided the following arguments: |
| 7 | + |
| 8 | + - v1: element from first input array. |
| 9 | + - v2: element from second input array. |
| 10 | + - idx: element index. |
| 11 | + - x: first input array. |
| 12 | + - y: second input array. |
| 13 | + |
| 14 | + The returned output array always has a "generic" data type. For example, if |
| 15 | + provided an array-like object, the function returns a generic array. If |
| 16 | + provided an ndarray, the function returns an ndarray having a "generic" data |
| 17 | + type. |
| 18 | + |
| 19 | + Input arrays must be either both array-like objects or both ndarray-like |
| 20 | + objects. |
| 21 | + |
| 22 | + If input arrays are array-like objects, the arrays must have the same number |
| 23 | + of elements. |
| 24 | + |
| 25 | + If input arrays are ndarray-like objects, the arrays must be broadcast |
| 26 | + compatible. |
| 27 | + |
| 28 | + Parameters |
| 29 | + ---------- |
| 30 | + x: ArrayLikeObject|ndarray |
| 31 | + First input array. |
| 32 | + |
| 33 | + y: ArrayLikeObject|ndarray |
| 34 | + Second input array. |
| 35 | + |
| 36 | + fcn: Function |
| 37 | + Function to apply. |
| 38 | + |
| 39 | + thisArg: any (optional) |
| 40 | + Input function context. |
| 41 | + |
| 42 | + Returns |
| 43 | + ------- |
| 44 | + out: Array|ndarray |
| 45 | + Output array. |
| 46 | + |
| 47 | + Examples |
| 48 | + -------- |
| 49 | + // array-like object: |
| 50 | + > var f = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); |
| 51 | + > var x = [ 1, 2, 3, 4, 5, 6 ]; |
| 52 | + > var y = [ 1, 1, 1, 1, 1, 1 ]; |
| 53 | + > var out = {{alias}}( x, y, f ) |
| 54 | + [ 2, 3, 4, 5, 6, 7 ] |
| 55 | + |
| 56 | + // ndarray: |
| 57 | + > x = {{alias:@stdlib/ndarray/array}}( x, { 'shape': [ 2, 3 ] } ); |
| 58 | + > y = {{alias:@stdlib/ndarray/array}}( y, { 'shape': [ 2, 3 ] } ); |
| 59 | + > out = {{alias}}( x, y, f ); |
| 60 | + > var v = out.get( 1, 1 ) |
| 61 | + 6 |
| 62 | + |
| 63 | + |
| 64 | +{{alias}}.assign( x, y, out, fcn[, thisArg] ) |
| 65 | + Applies a function to elements in two input arrays and assigns the results |
| 66 | + to an output array. |
| 67 | + |
| 68 | + The applied function is provided the following arguments: |
| 69 | + |
| 70 | + - v1: element from first input array. |
| 71 | + - v2: element from second input array. |
| 72 | + - idx: element index. |
| 73 | + - x: first input array. |
| 74 | + - y: second input array. |
| 75 | + |
| 76 | + Input and output arrays must be either all array-like objects or all |
| 77 | + ndarray-like objects. |
| 78 | + |
| 79 | + If input and output arrays are array-like objects, the arrays must have the |
| 80 | + same number of elements. |
| 81 | + |
| 82 | + If input and output arrays are ndarray-like objects, the arrays must be |
| 83 | + broadcast compatible. |
| 84 | + |
| 85 | + Parameters |
| 86 | + ---------- |
| 87 | + x: ArrayLikeObject|ndarray |
| 88 | + First input array. |
| 89 | + |
| 90 | + y: ArrayLikeObject|ndarray |
| 91 | + Second input array. |
| 92 | + |
| 93 | + out: ArrayLikeObject|ndarray |
| 94 | + Output array. |
| 95 | + |
| 96 | + fcn: Function |
| 97 | + Function to apply. |
| 98 | + |
| 99 | + thisArg: any (optional) |
| 100 | + Input function context. |
| 101 | + |
| 102 | + Returns |
| 103 | + ------- |
| 104 | + out: Array|ndarray |
| 105 | + Output array. |
| 106 | + |
| 107 | + Examples |
| 108 | + -------- |
| 109 | + // array-like object: |
| 110 | + > var f = {{alias:@stdlib/utils/nary-function}}( {{alias:@stdlib/math/base/ops/add}}, 2 ); |
| 111 | + > var x = [ 1, 2, 3, 4, 5, 6 ]; |
| 112 | + > var y = [ 1, 1, 1, 1, 1, 1 ]; |
| 113 | + > var out = [ 0, 0, 0, 0, 0, 0 ]; |
| 114 | + > {{alias}}.assign( x, y, out, f ); |
| 115 | + > out |
| 116 | + [ 2, 3, 4, 5, 6, 7 ] |
| 117 | + |
| 118 | + // ndarray: |
| 119 | + > var opts = { 'shape': [ 2, 3 ] }; |
| 120 | + > x = {{alias:@stdlib/ndarray/array}}( x, opts ); |
| 121 | + > y = {{alias:@stdlib/ndarray/array}}( y, opts ); |
| 122 | + > out = {{alias:@stdlib/ndarray/array}}( [ 0, 0, 0, 0, 0, 0 ], opts ); |
| 123 | + > {{alias}}.assign( x, y, out, f ); |
| 124 | + > var v = out.get( 1, 1 ) |
| 125 | + 6 |
| 126 | + |
| 127 | + See Also |
| 128 | + -------- |
| 129 | + |
0 commit comments