dongle7637 2018-02-28 22:44
浏览 158
已采纳

矩阵点积与python结果不同

I'm studying the multi-layer perceptron algorithm and I'm translating python code to golang.

I have 2 matrices. Let's call this matrix M1:

[[0 0 1 1]
 [0 1 0 1]]

Let's call this matrix M2:

[[ 0.00041597  0.02185088 -0.00362142]
 [-0.00057384 -0.02866677  0.00488404]
 [-0.00056316 -0.02705587  0.00410378]
 [ 0.00048268  0.01692128 -0.00262183]]

I'm implementing the dotProduct(M1,M2) in python and it gives me this result

[[ -8.04778516e-05  -1.01345901e-02   1.48194623e-03]
 [ -9.11603819e-05  -1.17454886e-02   2.26221011e-03]]

I'm doing it in golang with the same inputs matrix(M1,M2) but the golang code returns this matrix:

[[-8.047785157755936e-05 -0.010134590118173147 0.0014819462317188985]
 [-9.116038191682538e-05 -0.011745488603430228 0.0022622101145935328]]

In python I'm using numpy's dot operation:

resultMatrix = M1.dot(M2)

In go, I'm using this package to work with matrix in go
The problem here is because I calculate others dotProcut calculos with golang and it are all ok

I make N tests with other values, i'm using this package(the same dotProduct method) in others parts of this my code and all has been ok

My Go code at line 128
Tutorial Python code at line 61
Matrix golang package method that implemets the golang dotProduct at line 30

The code in python is not mine, and because this, the code it's written in Portuguese, but my go code is written in English

In python i know that's right because all the neural network works well, but in go I'm not sure

i read the matrix go package method many times and dont get the "bug code implementation", some one know where I'm wrong?

  • 写回答

1条回答 默认 最新

  • douzhe2981 2018-02-28 22:50
    关注

    Well, actually the results are pretty much the same. The thing that might confuse you is that formatting is different but still Python's -1.01345901e-02 = -0.0101345901 (see Scientific notation and particularly its E-notation" section) which is pretty close to Go's -0.010134590118173147 and just to make it clear let's align them

    Python -1.01345901e-02
    Go   -0.010134590118173147
    

    So if you have any problems in your code, they probably come from some other source than matrix multiplication.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。