php+矩阵,矩阵 · PHP-ML中文文档 · 看云

## 矩阵

> 将PHP数组包装到数学矩阵的类。

### 创建

要创建Matrix,请使用简单数组:

```

$matrix = new Matrix([

[3, 3, 3],

[4, 2, 1],

[5, 6, 7],

]);

```

您还可以从平面阵列创建Matrix(一维):

```

$flatArray = [1, 2, 3, 4];

$matrix = Matrix::fromFlatArray($flatArray);

```

*****

### 矩阵数据

从`Matrix`读取数据的方法:

```

$matrix->toArray(); // cast matrix to PHP array

$matrix->getRows(); // rows count

$matrix->getColumns(); // columns count

$matrix->getColumnValues($column=4); // get values from given column

```

*****

### 行列式

阅读有关[矩阵行列式](https://baike.baidu.com/item/%E7%9F%A9%E9%98%B5%E8%A1%8C%E5%88%97%E5%BC%8F/18882017?fr=aladdin)的更多信息

```

$matrix = new Matrix([

[3, 3, 3],

[4, 2, 1],

[5, 6, 7],

]);

$matrix->getDeterminant();

// return -3

```

*****

### 颠倒

阅读有关[矩阵转置](https://baike.baidu.com/item/%E7%9F%A9%E9%98%B5%E8%BD%AC%E7%BD%AE/4150715?fr=aladdin)的更多信息。

```

$matrix->transpose();

// return new Matrix

```

*****

### 乘

由另一个矩阵乘以矩阵。

```

$matrix1 = new Matrix([

[1, 2, 3],

[4, 5, 6],

]);

$matrix2 = new Matrix([

[7, 8],

[9, 10],

[11, 12],

]);

$matrix1->multiply($matrix2);

// result $product = [

// [58, 64],

// [139, 154],

//];

```

*****

### 除以标量

您可以通过标量值划分`Matrix`。

```

$matrix->divideByScalar(2);

```

*****

### 逆

阅读有关[可逆矩阵](https://baike.baidu.com/item/%E5%8F%AF%E9%80%86%E7%9F%A9%E9%98%B5/11035614)的更多信息

```

$matrix = new Matrix([

[3, 4, 2],

[4, 5, 5],

[1, 1, 1],

]);

$matrix->inverse();

// result $inverseMatrix = [

// [0, -1, 5],

// [1 / 2, 1 / 2, -7 / 2],

// [-1 / 2, 1 / 2, -1 / 2],

//];

```

*****

### 划出

从`Matrix`中划出给定的行和列。

```

$matrix = new Matrix([

[3, 4, 2],

[4, 5, 5],

[1, 1, 1],

]);

$matrix->crossOut(1, 1)

// result $crossOuted = [

// [3, 2],

// [1, 1],

//];

```

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值