# Request: I can't understand why a result of matrix multiplication in Julia like this

**URL:** https://discourse.julialang.org/t/request-i-cant-understand-why-a-result-of-matrix-multiplication-in-julia-like-this/42050
**Category:** General Usage
**Tags:** question
**Created:** [June 25, 2020, 4:17pm UTC](https://discourse.julialang.org/t/request-i-cant-understand-why-a-result-of-matrix-multiplication-in-julia-like-this/42050 "2020-06-25T16:17:26Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Hyeonji-Ryu](https://avatars.discourse-cdn.com/v4/letter/h/8c91f0/32.png) [@Hyeonji-Ryu](https://discourse.julialang.org/u/Hyeonji-Ryu)
#### Post date: [June 25, 2020, 4:17pm UTC](https://discourse.julialang.org/t/request-i-cant-understand-why-a-result-of-matrix-multiplication-in-julia-like-this/42050/1 "2020-06-25T16:17:27Z")

</div>

Hello, I’m a student using Julia in my project making deep learning model.  
I usually use ‘matrix multiplication’ a lot in my code.  
then, I found some result is weird.  
I think it’s better to show some examples than to explain.

```nohighlight
julia> temp = randn(3,3)
3×3 Array{Float64,2}:
 -0.354025 -0.12966 0.178489
 -1.26627 -0.648564 -1.39475
 -1.86577 0.401252 1.16448

julia> temp1 = rand(3,2)
3×2 Array{Float64,2}:
 0.346108 0.895262
 0.852009 0.508729
 0.201902 0.831357

julia> out = temp * temp1
3×2 Array{Float64,2}:
 -0.196965 -0.234519
 -1.27245 -2.62313
 -0.0687769 -0.498126

julia> out[1] # result_1
-0.19696523721990802

julia> sum(temp[1,:] .* temp1[:,1]) # result_2
-0.19696523721990805

```

as far as I know, ‘the result\_1’ and the ‘result\_2’ have to be same.  
I don’t know why the result like this.

---

<div class="post-metadata">

### Author: ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)
#### Post date: [June 25, 2020, 4:24pm UTC](https://discourse.julialang.org/t/request-i-cant-understand-why-a-result-of-matrix-multiplication-in-julia-like-this/42050/2 "2020-06-25T16:24:24Z")

</div>

Floating point numbers have finite precision, so they cannot represent all possible values. That means that doing math on floating point numbers will introduce small errors when the results need to be rounded to the nearest value that can be represented as a floating-point number. Those errors will be different depending on exactly how the calculations are ordered or combined, so you may get slightly different results by computing the same value in two different ways. This is normal and expected for all floating-point math in any programming language.

You can learn more about the topic here: [PSA: floating-point arithmetic](https://discourse.julialang.org/t/psa-floating-point-arithmetic/8678)

---

<div class="post-metadata">

### Author: ![Hyeonji-Ryu](https://avatars.discourse-cdn.com/v4/letter/h/8c91f0/32.png) [@Hyeonji-Ryu](https://discourse.julialang.org/u/Hyeonji-Ryu)
#### Post date: [June 25, 2020, 4:39pm UTC](https://discourse.julialang.org/t/request-i-cant-understand-why-a-result-of-matrix-multiplication-in-julia-like-this/42050/3 "2020-06-25T16:39:23Z")

</div>

oh…I see. Thank you for answering.🙂
