NDArray::prod
public static function prod(NDArray|array|float|int $a, ?int $axis = NULL): NDArray|float|int;
Calculates the product of all elements in the array over a given axis along which a product is performed.
The default, axis=NULL, will calculate the product of all the elements in the input array.
Parameters
$a
- Type -
NDArray
|array
|scalar
- Input array
$axis
- Type -
NDArray
|array
|scalar
- The axis to perform the product. If
$axis
is NULL, will calculate the product of all the elements of$a
.
Return
NDArray
- The product of
$a
. If$axis
is not NULL, the specified axis is removed.
Examples
- Example 1
- Example 2
- Example 3
use \NDArray as nd;
$a = new nd([[1, 2], [3, 4]]);
$c = nd::prod($a);
print_r($c);
24
use \NDArray as nd;
$c = nd::prod([[1, 2], [3, 4]], axis: 0);
print_r($c);
[3, 8]
use \NDArray as nd;
$a = new nd([[1, 2], [3, 4]]);
$c = nd::prod($a, axis: 1);
print_r($c);
[2, 12]