PHP—ML 算法,矩阵返回的对象,里面的值如何取出来?
composer require php-ai/php-ml先安装 composer require php-ai/php-ml
上源码
<?php
require_once __DIR__ . '/vendor/autoload.php';
use Phpml\Math\Matrix;
$matrix1 = new Matrix([
[1, 2, 3],
[4, 5, 6],
]);
$matrix2 = new Matrix([
[7, 8],
[9, 10],
[11, 12],
]);
$res = $matrix1->multiply($matrix2);
var_dump($res);
需求,如何返回$res这个对象里,两个数组的值?
$res的结果如下!
object(Phpml\Math\Matrix)#4 (4) {
["matrix":"Phpml\Math\Matrix":private]=>
array(2) {
[0]=>
array(2) {
[0]=>
int(58)
[1]=>
int(64)
}
[1]=>
array(2) {
[0]=>
int(139)
[1]=>
int(154)
}
}
["rows":"Phpml\Math\Matrix":private]=>
int(2)
["columns":"Phpml\Math\Matrix":private]=>
int(2)
["determinant":"Phpml\Math\Matrix":private]=>
NULL
}
本作品采用《CC 协议》,转载必须注明作者和本文链接
composer require php-ai/php-ml 先安装这个开源模块!
你打印出来的
$res
是什么样子的呐var_dump($res->toArray());
php-ml.readthedocs.org/