Matrix multiplication in php

前端 未结 3 1570
难免孤独
难免孤独 2021-01-26 17:29

Although the order of matrices should be fine, the following code throws back the exception. It might be a tiny thing I\'m not being able to notice, but can\'t figure it out.

3条回答
  •  一向
    一向 (楼主)
    2021-01-26 17:56

    You're specifying your test matrices wrong, in two ways:

    1. The arrays aren't two-dimensional (that is, arrays of arrays of numbers).
    2. Even if you wrapped another array( ) around them, the condition that the width of the first matrix be equal to the height of the second matrix doesn't hold with [5 1] and [1 5], which are both 2 wide and 1 high.

    What you need is something like

    $mat1 = array(array(5,1));
    $mat2 = array(array(1),array(5));
    

提交回复
热议问题