|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2024 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 | +# mskbinary4d |
| 22 | + |
| 23 | +> Apply a binary callback to elements in two four-dimensional nested input arrays according to elements in a four-dimensional nested mask array and assign results to elements in a four-dimensional nested output array. |
| 24 | +
|
| 25 | +<section class="intro"> |
| 26 | + |
| 27 | +</section> |
| 28 | + |
| 29 | +<!-- /.intro --> |
| 30 | + |
| 31 | +<section class="usage"> |
| 32 | + |
| 33 | +## Usage |
| 34 | + |
| 35 | +```javascript |
| 36 | +var mskbinary4d = require( '@stdlib/array/base/mskbinary4d' ); |
| 37 | +``` |
| 38 | + |
| 39 | +#### mskbinary4d( arrays, shape, fcn ) |
| 40 | + |
| 41 | +Applies a binary callback to elements in two four-dimensional nested input arrays according to elements in a four-dimensional nested mask array and assigns results to elements in a four-dimensional nested output array. |
| 42 | + |
| 43 | +```javascript |
| 44 | +var add = require( '@stdlib/math/base/ops/add' ); |
| 45 | +var zeros4d = require( '@stdlib/array/base/zeros4d' ); |
| 46 | + |
| 47 | +var x = [ [ [ [ 1.0, 2.0 ], [ 3.0, 4.0 ] ] ] ]; |
| 48 | +var z = zeros4d( [ 1, 1, 2, 2 ] ); |
| 49 | + |
| 50 | +var mask = [ [ [ [ 0, 1 ], [ 0, 0 ] ] ] ]; |
| 51 | + |
| 52 | +var shape = [ 1, 1, 2, 2 ]; |
| 53 | + |
| 54 | +mskbinary4d( [ x, x, mask, z ], shape, add ); |
| 55 | +// z => [ [ [ [ 2.0, 0.0 ], [ 6.0, 8.0 ] ] ] ] |
| 56 | +``` |
| 57 | + |
| 58 | +The function accepts the following arguments: |
| 59 | + |
| 60 | +- **arrays**: array-like object containing two input nested arrays, an input nested mask array, and one output nested array. |
| 61 | +- **shape**: array shape. |
| 62 | +- **fcn**: binary function to apply. |
| 63 | + |
| 64 | +</section> |
| 65 | + |
| 66 | +<!-- /.usage --> |
| 67 | + |
| 68 | +<section class="notes"> |
| 69 | + |
| 70 | +## Notes |
| 71 | + |
| 72 | +- The function assumes that the input and output arrays have the same shape. |
| 73 | + |
| 74 | +</section> |
| 75 | + |
| 76 | +<!-- /.notes --> |
| 77 | + |
| 78 | +<section class="examples"> |
| 79 | + |
| 80 | +## Examples |
| 81 | + |
| 82 | +<!-- eslint no-undef: "error" --> |
| 83 | + |
| 84 | +```javascript |
| 85 | +var discreteUniform = require( '@stdlib/random/base/discrete-uniform' ).factory; |
| 86 | +var bernoulli = require( '@stdlib/random/base/bernoulli' ).factory; |
| 87 | +var filled4dBy = require( '@stdlib/array/base/filled4d-by' ); |
| 88 | +var zeros4d = require( '@stdlib/array/base/zeros4d' ); |
| 89 | +var add = require( '@stdlib/math/base/ops/add' ); |
| 90 | +var mskbinary4d = require( '@stdlib/array/base/mskbinary4d' ); |
| 91 | + |
| 92 | +var shape = [ 2, 1, 3, 3 ]; |
| 93 | + |
| 94 | +var x = filled4dBy( shape, discreteUniform( -100, 100 ) ); |
| 95 | +console.log( x ); |
| 96 | + |
| 97 | +var y = filled4dBy( shape, discreteUniform( -100, 100 ) ); |
| 98 | +console.log( y ); |
| 99 | + |
| 100 | +var mask = filled4dBy( shape, bernoulli( 0.5 ) ); |
| 101 | +console.log( mask ); |
| 102 | + |
| 103 | +var z = zeros4d( shape ); |
| 104 | +console.log( z ); |
| 105 | + |
| 106 | +mskbinary4d( [ x, y, mask, z ], shape, add ); |
| 107 | +console.log( z ); |
| 108 | +``` |
| 109 | + |
| 110 | +</section> |
| 111 | + |
| 112 | +<!-- /.examples --> |
| 113 | + |
| 114 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 115 | + |
| 116 | +<section class="related"> |
| 117 | + |
| 118 | +</section> |
| 119 | + |
| 120 | +<!-- /.related --> |
| 121 | + |
| 122 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 123 | + |
| 124 | +<section class="links"> |
| 125 | + |
| 126 | +</section> |
| 127 | + |
| 128 | +<!-- /.links --> |
0 commit comments