NumPHP\Core\NumArray::mean PHP Method

mean() public method

Returns the mean of the NumArray for the given axis
Since: 1.0.0
public mean ( integer $axis = null ) : NumArray
$axis integer given axis of mean
return NumArray
    public function mean($axis = null)
    {
        $divisor = $this->getSize();
        if (array_key_exists($axis, $this->shape)) {
            $divisor = $this->shape[$axis];
        }
        return $this->sum($axis)->dot(1 / $divisor);
    }

Usage Example

コード例 #1
0
ファイル: MeanTest.php プロジェクト: buaa556/gongkesheng
 /**
  * Tests NumArray::mean with a matrix and argument 1
  */
 public function testMeanMatrixAxis1()
 {
     $numArray = new NumArray([[12, -43, 6], [-3, 89, 23]]);
     $expectedNumArray = new NumArray([-25 / 3, 109 / 3]);
     $this->assertNumArrayEquals($expectedNumArray, $numArray->mean(1));
 }