NumPHP\Core\NumArray::sum PHP Method

sum() public method

Summed all elements of an NumArray for the given axis
Since: 1.0.0
public sum ( integer $axis = null ) : NumArray
$axis integer given axis of sum
return NumArray
    public function sum($axis = null)
    {
        return Reduce::reduceArray($this, function ($data1, $data2) {
            return $data1 + $data2;
        }, $axis);
    }

Usage Example

Example #1
0
 /**
  * Tests if InvalidArgumentException will be thrown by using NumArray::sum and a
  * wrong axis on a scalar value
  *
  * @expectedException        \NumPHP\Core\Exception\InvalidArgumentException
  * @expectedExceptionMessage Axis 1 out of bounds
  */
 public function testSumSingleAxis1()
 {
     $numArray = new NumArray(6);
     $numArray->sum(1);
 }