|
| 1 | +# Arithmetic Routines |
| 2 | + |
| 3 | +--- |
| 4 | + |
| 5 | +## add |
| 6 | +```php |
| 7 | +public static add($x1, $x2) : CArray |
| 8 | +``` |
| 9 | +> Add arguments element-wise. |
| 10 | +
|
| 11 | +##### Parameters |
| 12 | + |
| 13 | +`CArray|Array` **$x1** **$x2** Input arrays. |
| 14 | + |
| 15 | +##### Returns |
| 16 | + |
| 17 | +`CArray` The sum of `$x1` and `$x2`, element-wise. |
| 18 | + |
| 19 | +##### Examples |
| 20 | + |
| 21 | +**Example 1** |
| 22 | +```php |
| 23 | +$x1 = CArray::arange(9.0); |
| 24 | +$x1 = CArray::reshape($x1, [3, 3]); |
| 25 | +$x2 = CArray::arange(3.0); |
| 26 | + |
| 27 | +echo CArray::add($x1, $x2); |
| 28 | +``` |
| 29 | +``` |
| 30 | +[[ 0 2 4 ] |
| 31 | + [ 3 5 7 ] |
| 32 | + [ 6 8 10 ]] |
| 33 | +``` |
| 34 | + |
| 35 | +**Example 2** |
| 36 | +```php |
| 37 | +$a = new CArray([[1, 2], [3, 4]]); |
| 38 | +$b = new CArray([[5, 6], [7, 8]]); |
| 39 | + |
| 40 | +$c = $a + $b; // Same as CArray::add |
| 41 | + |
| 42 | +echo $c; |
| 43 | +``` |
| 44 | +``` |
| 45 | +[[ 6 8 ] |
| 46 | + [ 10 12 ]] |
| 47 | +``` |
| 48 | + |
| 49 | +--- |
| 50 | + |
| 51 | +## subtract |
| 52 | +```php |
| 53 | +public static subtract($x1, $x2) : CArray |
| 54 | +``` |
| 55 | +> Subtract arguments element-wise. |
| 56 | +
|
| 57 | +##### Parameters |
| 58 | + |
| 59 | +`CArray|Array` **$x1** **$x2** Input arrays. |
| 60 | + |
| 61 | +##### Returns |
| 62 | + |
| 63 | +`CArray` The difference of `$x1` and `$x2`, element-wise. |
| 64 | + |
| 65 | +##### Examples |
| 66 | + |
| 67 | +**Example 1** |
| 68 | +```php |
| 69 | +$x1 = CArray::arange(9.0); |
| 70 | +$x1 = CArray::reshape($x1, [3, 3]); |
| 71 | +$x2 = CArray::arange(3.0); |
| 72 | +echo CArray::subtract($x1, $x2); |
| 73 | +``` |
| 74 | +``` |
| 75 | +[[ 0 0 0 ] |
| 76 | + [ 3 3 3 ] |
| 77 | + [ 6 6 6 ]] |
| 78 | +``` |
| 79 | + |
| 80 | +**Example 2** |
| 81 | +```php |
| 82 | +$x1 = CArray::arange(9.0); |
| 83 | +$x1 = CArray::reshape($x1, [3, 3]); |
| 84 | +$x2 = CArray::arange(3.0); |
| 85 | +echo ($x1 - $x2); |
| 86 | +``` |
| 87 | +``` |
| 88 | +[[ 0 0 0 ] |
| 89 | + [ 3 3 3 ] |
| 90 | + [ 6 6 6 ]] |
| 91 | +``` |
| 92 | + |
| 93 | +--- |
| 94 | + |
| 95 | +## multiply |
| 96 | +```php |
| 97 | +public static multiply($x1, $x2) : CArray |
| 98 | +``` |
| 99 | +> Multiply arguments element-wise. |
| 100 | +
|
| 101 | +##### Parameters |
| 102 | + |
| 103 | +`CArray|Array` **$x1** **$x2** Input arrays. |
| 104 | + |
| 105 | +##### Returns |
| 106 | + |
| 107 | +`CArray` The multiplication of `$x1` and `$x2`, element-wise. |
| 108 | + |
| 109 | +##### Examples |
| 110 | + |
| 111 | +**Example 1** |
| 112 | +```php |
| 113 | +$x1 = CArray::arange(9.0); |
| 114 | +$x1 = CArray::reshape($x1, [3, 3]); |
| 115 | +$x2 = CArray::arange(3.0); |
| 116 | +echo CArray::multiply($x1, $x2); |
| 117 | +``` |
| 118 | +``` |
| 119 | +[[ 0 1 4 ] |
| 120 | + [ 0 4 10 ] |
| 121 | + [ 0 7 16 ]] |
| 122 | +``` |
| 123 | + |
| 124 | +**Example 2** |
| 125 | +```php |
| 126 | +$x1 = CArray::arange(9.0); |
| 127 | +$x1 = CArray::reshape($x1, [3, 3]); |
| 128 | +$x2 = CArray::arange(3.0); |
| 129 | +echo ($x1 * $x2); |
| 130 | +``` |
| 131 | +``` |
| 132 | +[[ 0 1 4 ] |
| 133 | + [ 0 4 10 ] |
| 134 | + [ 0 7 16 ]] |
| 135 | +``` |
| 136 | + |
| 137 | +--- |
| 138 | + |
| 139 | +## divide |
| 140 | +```php |
| 141 | +public static divide($x1, $x2) : CArray |
| 142 | +``` |
| 143 | +> Returns a true division of the inputs, element-wise. |
| 144 | +
|
| 145 | +##### Parameters |
| 146 | + |
| 147 | +`CArray|Array` **$x1** Dividend |
| 148 | + |
| 149 | +`CArray|Array` **$x2** Divisor |
| 150 | + |
| 151 | +##### Returns |
| 152 | + |
| 153 | +`CArray` Return array. |
| 154 | + |
| 155 | +##### Examples |
| 156 | + |
| 157 | +**Example 1** |
| 158 | +```php |
| 159 | +echo CArray::divide([1, 2, 3, 4, 5], 4); |
| 160 | +``` |
| 161 | +``` |
| 162 | +[ 0.25000000 0.50000000 0.75000000 1.00000000 1.25000000 ] |
| 163 | +``` |
| 164 | + |
| 165 | +**Example 2** |
| 166 | +```php |
| 167 | +$a = new CArray([[1, 2], [3, 4]]); |
| 168 | +echo ($a / 4); |
| 169 | +``` |
| 170 | +``` |
| 171 | +[[ 0.25000000 0.50000000 ] |
| 172 | + [ 0.75000000 1.00000000 ]] |
| 173 | +``` |
| 174 | + |
| 175 | +--- |
| 176 | + |
| 177 | +## power |
| 178 | +```php |
| 179 | +public static power($x1, $x2) : CArray |
| 180 | +``` |
| 181 | +> `$x1` array elements raised to powers from `$x2` array, element-wise. |
| 182 | +
|
| 183 | +##### Parameters |
| 184 | + |
| 185 | +`CArray|Array` **$x1** Bases |
| 186 | + |
| 187 | +`CArray|Array` **$x2** Exponents |
| 188 | + |
| 189 | +##### Returns |
| 190 | + |
| 191 | +`CArray` The bases in `$x1` raised to the exponents in `$x2`. |
| 192 | + |
| 193 | +##### Examples |
| 194 | + |
| 195 | +**Example 1** |
| 196 | +```php |
| 197 | +$x1 = CArray::arange(6); |
| 198 | +echo CArray::power($x1, 3); |
| 199 | +``` |
| 200 | +``` |
| 201 | +[ 0 1 8 27 64 125 ] |
| 202 | +``` |
| 203 | + |
| 204 | +--- |
| 205 | + |
| 206 | +## mod |
| 207 | +```php |
| 208 | +public static mod($x1, $x2) : CArray |
| 209 | +``` |
| 210 | +> Return element-wise remainder of division. |
| 211 | +
|
| 212 | +##### Parameters |
| 213 | + |
| 214 | +`CArray|Array` **$x1** Dividend |
| 215 | + |
| 216 | +`CArray|Array` **$x2** Divisor |
| 217 | + |
| 218 | +##### Returns |
| 219 | + |
| 220 | +`CArray` The element-wise remainder |
| 221 | + |
| 222 | +##### Examples |
| 223 | + |
| 224 | +**Example 1** |
| 225 | +```php |
| 226 | +echo CArray::mod([4, 7], [2, 3]); |
| 227 | +``` |
| 228 | +``` |
| 229 | +[ 0. 1. ] |
| 230 | +``` |
| 231 | + |
| 232 | +--- |
| 233 | + |
| 234 | +## remainder |
| 235 | +```php |
| 236 | +public static remainder($x1, $x2) : CArray |
| 237 | +``` |
| 238 | +> Return element-wise remainder of division. |
| 239 | +
|
| 240 | +##### Parameters |
| 241 | + |
| 242 | +`CArray|Array` **$x1** Dividend |
| 243 | + |
| 244 | +`CArray|Array` **$x2** Divisor |
| 245 | + |
| 246 | +##### Returns |
| 247 | + |
| 248 | +`CArray` The element-wise remainder |
| 249 | + |
| 250 | +##### Examples |
| 251 | + |
| 252 | +**Example 1** |
| 253 | +```php |
| 254 | +echo CArray::remainder([4, 7], [2, 3]); |
| 255 | +``` |
| 256 | +``` |
| 257 | +[ 0. 1. ] |
| 258 | +``` |
| 259 | + |
| 260 | +--- |
| 261 | + |
| 262 | +## negative |
| 263 | +```php |
| 264 | +public static negative($x) : CArray |
| 265 | +``` |
| 266 | +> Numerical negative, element-wise. |
| 267 | +
|
| 268 | +##### Parameters |
| 269 | + |
| 270 | +`CArray|Array` **$x** Input array. |
| 271 | + |
| 272 | +##### Returns |
| 273 | + |
| 274 | +`CArray` Return array. |
| 275 | + |
| 276 | +##### Examples |
| 277 | + |
| 278 | +**Example 1** |
| 279 | +```php |
| 280 | +echo CArray::negative([1, -1]); |
| 281 | +``` |
| 282 | +``` |
| 283 | +[ -1. 1. ] |
| 284 | +``` |
| 285 | + |
| 286 | + |
| 287 | +--- |
| 288 | + |
| 289 | +## sqrt |
| 290 | +```php |
| 291 | +public static sqrt($x) : CArray |
| 292 | +``` |
| 293 | + |
| 294 | +--- |
| 295 | + |
| 296 | +## reciprocal |
| 297 | +```php |
| 298 | +public static reciprocal($x) : CArray |
| 299 | +``` |
| 300 | +> Return `1/$x` of the argument, element-wise. |
| 301 | +
|
| 302 | +##### Parameters |
| 303 | + |
| 304 | +`CArray|Array` **$x** Input array. |
| 305 | + |
| 306 | +##### Returns |
| 307 | + |
| 308 | +`CArray` Return array. |
| 309 | + |
| 310 | +##### Examples |
| 311 | + |
| 312 | +**Example 1** |
| 313 | +```php |
| 314 | +echo CArray::reciprocal([1, 2., 3.33]); |
| 315 | +``` |
| 316 | +``` |
| 317 | +[ 1.00000000 0.50000000 0.33333333 ] |
| 318 | +``` |
| 319 | + |
| 320 | + |
| 321 | + |
| 322 | + |
0 commit comments