/** * Combines all elements of an NumArray at a given axis with the `$callback` * function * * @param NumArray $numArray given NumArray * @param callback $callback callback function * @param int $axis given axis * * @return NumArray * * @throws InvalidArgumentException will be thrown, if axis is out of bounds * * @since 1.0.0 */ public static function reduceArray(NumArray $numArray, $callback, $axis) { if ($axis && $axis >= $numArray->getNDim()) { throw new InvalidArgumentException('Axis ' . $axis . ' out of bounds'); } return new NumArray(self::reduceRecursive($numArray->getData(), $callback, $axis)); }
/** * Tests NumArray::getNDim */ public function testNDim() { $numArray = new NumArray(1); $this->assertSame(0, $numArray->getNDim()); $numArray = NumPHP::arange(1, 2); $this->assertSame(1, $numArray->getNDim()); $numArray = NumPHP::arange(1, 6)->reshape(2, 3); $this->assertSame(2, $numArray->getNDim()); }
/** * Tests if a NumArray is a vector * * @param NumArray $numArray given NumArray * * @return bool * * @since 1.0.0 */ public static function isVector(NumArray $numArray) { return $numArray->getNDim() === 1; }