# No method matching zero(::Type{Array{Float64,2}})

**URL:** <https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538>\
**Category:** Data\
**Tags:** question, package\
**Created:** [March 19, 2021, 1:47pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538 "2021-03-19T13:47:53Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shazman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shazman/32/23093_2.png) [@Shazman](https://discourse.julialang.org/u/Shazman)\
**Post date:** [March 19, 2021, 1:47pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/1 "2021-03-19T13:47:53Z")

</div>

Hi,

I am using Julia to solve the equation below, where  
XS is a large matrix and XT is a transpose version of XS.  
LamI is a diagonal matrix and RHS is a vector.

> using DelimitedFiles  
> using LinearAlgebra  
> XS = readdlm(“XS.txt”)  
> RHS = readdlm(“rhs.txt”)  
> LamI = readdlm(“LamI.txt”)  
> XT=XS’  
> MME= XT_XS + LamI  
> b = MME\RHS  
> GEBV=XS_b

Error I got

> ERROR: LoadError: MethodError: no method matching zero(::Type{Array{Float64,2}})

how can I fix it? thank you in advance.

---

<div class="post-metadata">

**Author:** ![Jordan\_Cluts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jordan_cluts/32/13753_2.png) [@Jordan\_Cluts](https://discourse.julialang.org/u/Jordan_Cluts)\
**Post date:** [March 19, 2021, 3:27pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/2 "2021-03-19T15:27:10Z")

</div>

If you could post a bit more of the error message or a MWE that would be helpful.

To me the concerning thing is the `Type` part of the error. That seems to imply you are passing in an Array Datatype instead of an actual Array.

---

<div class="post-metadata">

**Author:** ![Shazman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shazman/32/23093_2.png) [@Shazman](https://discourse.julialang.org/u/Shazman)\
**Post date:** [March 19, 2021, 3:36pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/3 "2021-03-19T15:36:50Z")

</div>

yes, my datasets were Arrays from Julia, then I want to import data as an array to do the calculation,

here is the complete error.

> ERROR: LoadError: MethodError: no method matching zero(::Type{Array{Float64,2}})  
> Closest candidates are:  
> zero(!Matched::Type{Missing}) at missing.jl:103  
> zero(!Matched::Type{Dates.Time}) at /buildworker/worker/package\_linux64/build/usr/share/julia/stdlib/v1.5/Dates/src/types.jl:406  
> zero(!Matched::Type{LibGit2.GitHash}) at /buildworker/worker/package\_linux64/build/usr/share/julia/stdlib/v1.5/LibGit2/src/oid.jl:220  
> …  
> Stacktrace:  
> [1] pinv(::Array{Array{Float64,2},1}) at /buildworker/worker/package\_linux64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/generic.jl:1054  
> [2] (::Array{Array{Float64,2},1}, ::Array{Float64,2}) at /buildworker/worker/package\_linux64/build/usr/share/julia/stdlib/v1.5/LinearAlgebra/src/generic.jl:1121  
> [3] top-level scope at /net/fs-1/home01/wubu/.julia/environments/v1.5/jcode.jl:16  
> [4] include(::Function, ::Module, ::String) at ./Base.jl:380  
> [5] include(::Module, ::String) at ./Base.jl:368  
> [6] exec\_options(::Base.JLOptions) at ./client.jl:296  
> [7] \_start() at ./client.jl:506  
> in expression starting at /net/fs-1/home01/wubu/.julia/environments/v1.5/jcode.jl:16

the code `b = RHS/MME` is `(jcode.jl:16)`,  
seems I have problem with the vector and arrays type.

---

<div class="post-metadata">

**Author:** ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)\
**Post date:** [March 19, 2021, 3:52pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/4 "2021-03-19T15:52:51Z")

</div>

This looks like `RHS` is a vector of matrices, not a matrix.

Aside from that, please use triple backticks (```) for code blocks, not quotations. Otherwise, some characters are swallowed (in your original code block, there are some `*` missing because they are used to toggle italics).

---

<div class="post-metadata">

**Author:** ![Shazman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shazman/32/23093_2.png) [@Shazman](https://discourse.julialang.org/u/Shazman)\
**Post date:** [March 19, 2021, 4:04pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/5 "2021-03-19T16:04:49Z")

</div>

yes, how can I fix the issue about `RHS`?

---

<div class="post-metadata">

**Author:** ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)\
**Post date:** [March 19, 2021, 4:39pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/6 "2021-03-19T16:39:27Z")

</div>

That depends on what you want to do. I assume you want a vector of numbers instead of a vector of matrices? I don’t understand how you get a vector of matrices in the first place, I think `readdlm` always returns a matrix. How is the rhs.txt file formatted?

Also, the stacktrace implies that you call `\`, not `/`, which is it?

---

<div class="post-metadata">

**Author:** ![Shazman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shazman/32/23093_2.png) [@Shazman](https://discourse.julialang.org/u/Shazman)\
**Post date:** [March 19, 2021, 4:52pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/7 "2021-03-19T16:52:56Z")

</div>

yes, I want a vector of numbers, when I open the `RHS`, it is a one-column vector with numbers.  
I do not understand why matrix format and vector format matters for `RHS` in this case.  
and I thought `b = RHS\MME` and `b = MEE/RHS` are same.

---

<div class="post-metadata">

**Author:** ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)\
**Post date:** [March 19, 2021, 5:17pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/8 "2021-03-19T17:17:54Z")

</div>

> [@Shazman](#):
>
> I do not understand why matrix format and vector format matters for `RHS` in this case.

It would not matter whether `RHS` is a vector or a matrix if its elements were numbers. However, in this case, `RHS` is a vector that contains _matrices_.

> [@Shazman](#):
>
> I thought `b = RHS\MME` and `b = MEE/RHS` are same.

Not necessarily, although they are the same for numbers. Similar to how `A*B` and `B*A` are different if `A` and `B` are matrices, `A/B` is equal to `(B'\A')'`

---

<div class="post-metadata">

**Author:** ![Shazman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shazman/32/23093_2.png) [@Shazman](https://discourse.julialang.org/u/Shazman)\
**Post date:** [March 19, 2021, 5:33pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/9 "2021-03-19T17:33:39Z")

</div>

ok, altough I do not how to solve the problem, I am pretty sure that `RHS` is a vector with numbers. and for calculating `b`, I should use `b = MEE/RHS`.

---

<div class="post-metadata">

**Author:** ![sostock](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sostock/32/5546_2.png) [@sostock](https://discourse.julialang.org/u/sostock)\
**Post date:** [March 19, 2021, 5:39pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/10 "2021-03-19T17:39:11Z")

</div>

Can you check the types of the objects? For example, put

```julia
@show typeof(XS)
@show typeof(RHS)
@show typeof(LamI)

```

in your code.

---

<div class="post-metadata">

**Author:** ![Shazman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shazman/32/23093_2.png) [@Shazman](https://discourse.julialang.org/u/Shazman)\
**Post date:** [March 19, 2021, 6:30pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/11 "2021-03-19T18:30:38Z")

</div>

those are the data types and then I saved those file saved as `txt` file using `DelimitedFiles`

```julia
typeof(XS) = Array{Float16,2}
@show typeof(LamI)
typeof(LamI) = Array{Float64,2}
@show typeof(RHS)
typeof(RHS) = Array{Float64,1}
```

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [March 19, 2021, 6:51pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/12 "2021-03-19T18:51:35Z")

</div>

Unfortunately it is kind of difficult to help with so little information. Could you paste a way to reproduce your arrays? Maybe uploading a smaller version of them and/or how to create them. It will be easier to debug then.

For example, in your code you don’t show the definition of `XTXS`, which you are using then when you do

```julia
MME= XTXS + LamI
b = RHS/MME

```

You can take a look at this thread with advice on what kind of info would make it easier.  
[PSA: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757)

---

<div class="post-metadata">

**Author:** ![Shazman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/shazman/32/23093_2.png) [@Shazman](https://discourse.julialang.org/u/Shazman)\
**Post date:** [March 19, 2021, 8:52pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/13 "2021-03-19T20:52:26Z")

</div>

here is my small part of data,  
and it is working, and I do not understand why I got `MethodError`, when I use `b = MME/RHS`  
I got error `ERROR: DimensionMismatch("Both inputs should have the same number of columns")`

> RHS[1:5,:]  
> 5×1 Array{Float64,2}:  
> -463.784842149869  
> 613.3235123884596  
> 344.87395521407393  
> -474.745592135491  
> -84.87248412192399

> LamI[1:5,1:5]  
> 5×5 Array{Float64,2}:  
> 60928.0 0.0 0.0 0.0 0.0  
> 0.0 60928.0 0.0 0.0 0.0  
> 0.0 0.0 60928.0 0.0 0.0  
> 0.0 0.0 0.0 60928.0 0.0  
> 0.0 0.0 0.0 0.0 60928.0

> XS[1:5,1:5]  
> 5×5 Array{Float16,2}:  
> -1.036 1.006 0.2256 0.38 -1.691  
> -0.03613 0.006348 0.2256 0.38 -0.6914  
> -0.03613 0.006348 -0.7744 0.38 0.3086  
> -0.03613 0.006348 0.2256 -0.62 0.3086  
> 0.964 -0.9937 0.2256 -0.62 0.3086

> MME = XS’ \* XS + LamI  
> 5×5 Array{Float64,2}:  
> 60930.0 -2.0 -0.00476074 -0.996094 2.05469  
> -2.0 60930.0 0.000854492 0.999023 -2.00781  
> -0.00476074 0.000854492 60928.8 -0.402588 -0.636719  
> -0.996094 0.999023 -0.402588 60929.2 -1.1709  
> 2.05469 -2.00781 -0.636719 -1.1709 60931.6

> b = MME\RHS  
> 5×1 Array{Float64,2}:  
> -0.007611513860004633  
> 0.0100658671109758  
> 0.0056602111208895285  
> -0.0077920367386778286  
> -0.0013924157031305455

> GEBV = XS\*b  
> 5×1 Array{Float64,2}:  
> 0.018683329887863184  
> -0.00038155181207251366  
> -0.007434178636092588  
> 0.006018069223474769  
> -0.011659311747505664

---

<div class="post-metadata">

**Author:** ![aramirezreyes](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aramirezreyes/32/42573_2.png) [@aramirezreyes](https://discourse.julialang.org/u/aramirezreyes)\
**Post date:** [March 19, 2021, 9:29pm UTC](https://discourse.julialang.org/t/no-method-matching-zero-type-array-float64-2/57538/14 "2021-03-19T21:29:20Z")

</div>

So it is working now? Great.

The error about the column number is probably related to

> [@sostock](#):
>
> `Similar to how A*B and B*A are different if A and B are matrices, A/B is equal to (B'\A')''`

When you transpose the vector RHS you get only one column and many rows, or viceversa, then the operation is not possible. If MME is a square matrix, its number of rows and columns do not change when transposing.
