zeros() 공개 정적인 메소드

Returns a NumArray filled with 0
부터: 1.0.0
public static zeros ( ) : NumArray
리턴 NumArray
예제 #1
0
파일: DotTest.php 프로젝트: raslin/NumPHP
 /**
  * Tests NumArray::dot with empty vectors
  */
 public function testDotEmptyVectorVector()
 {
     $vector1 = NumPHP::zeros(0);
     $vector2 = NumPHP::zeros(0);
     $expectedNumArray = new NumArray(0);
     $this->assertNumArrayEquals($expectedNumArray, $vector1->dot($vector2));
 }
예제 #2
0
 /**
  * @param NumArray $matrix
  * @param NumArray $vector
  * @return NumArray
  */
 protected static function backSubstitution(NumArray $matrix, NumArray $vector)
 {
     $shape = $matrix->getShape();
     $xVector = \NumPHP\Core\NumPHP::zeros($shape[0]);
     for ($i = $shape[0] - 1; $i >= 0; $i--) {
         $sum = 0;
         for ($j = $i + 1; $j < $shape[0]; $j++) {
             $sum += $matrix->get($i, $j)->dot($xVector->get($j))->getData();
         }
         $xVector->set($i, ($vector->get($i)->getData() - $sum) / $matrix->get($i, $i)->getData());
     }
     return $xVector;
 }
예제 #3
0
 /**
  * Tests NumArray::getSize on a 2x3x4 matrix
  */
 public function getSize2x3x4()
 {
     $numArray = NumPHP::zeros(2, 3, 4);
     $this->assertSame(24, $numArray->getSize());
 }
예제 #4
0
 /**
  * Build the upper triangular matrix from given matrix
  *
  * @param NumArray $numArray given matrix
  *
  * @return NumArray
  *
  * @since 1.0.0
  */
 protected static function buildUMatrix(NumArray $numArray)
 {
     $shape = $numArray->getShape();
     $nAxis = $shape[1];
     $size = min($shape[0], $nAxis);
     $uMatrix = NumPHP::zeros($size, $nAxis);
     for ($i = 0; $i < $size; $i++) {
         $slice = sprintf("%d:", $i);
         $uMatrix->set($i, $slice, $numArray->get($i, $slice));
     }
     return $uMatrix;
 }
예제 #5
0
 /**
  * Tests NumArray::getShape on matrix size 2x4
  */
 public function testGetShape2x4()
 {
     $numArray = NumPHP::zeros(2, 4);
     $this->assertSame([2, 4], $numArray->getShape());
 }
예제 #6
0
 /**
  * Tests NumPHP::zerosLike with 2x3 matrix
  */
 public function testZerosLike()
 {
     $numArray = new NumArray([[1, 2, 3], [4, 5, 6]]);
     $expectedNumArray = NumPHP::zeros(2, 3);
     $this->assertNumArrayEquals($expectedNumArray, NumPHP::zerosLike($numArray));
 }