# DimensionMismatch ("A has dimensions (1, 0) but B has dimensions (5,)") How to eliminate this error?

**URL:** https://discourse.julialang.org/t/dimensionmismatch-a-has-dimensions-1-0-but-b-has-dimensions-5-how-to-eliminate-this-error/12741
**Category:** Optimization (Mathematical)
**Created:** [July 30, 2018, 2:52pm UTC](https://discourse.julialang.org/t/dimensionmismatch-a-has-dimensions-1-0-but-b-has-dimensions-5-how-to-eliminate-this-error/12741 "2018-07-30T14:52:34Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)
#### Post date: [July 30, 2018, 2:52pm UTC](https://discourse.julialang.org/t/dimensionmismatch-a-has-dimensions-1-0-but-b-has-dimensions-5-how-to-eliminate-this-error/12741/1 "2018-07-30T14:52:34Z")

</div>

DimensionMismatch (“A has dimensions (1, 0) but B has dimensions (5,)”)  
How to eliminate this error?

---

<div class="post-metadata">

### Author: ![ggggggggg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ggggggggg/32/265_2.png) [@ggggggggg](https://discourse.julialang.org/u/ggggggggg)
#### Post date: [July 30, 2018, 3:33pm UTC](https://discourse.julialang.org/t/dimensionmismatch-a-has-dimensions-1-0-but-b-has-dimensions-5-how-to-eliminate-this-error/12741/2 "2018-07-30T15:33:12Z")

</div>

You’re more likely to get useful feedback if you can provide a small copy and pasteable example that demonstrates the problem. Also be sure to [quote your code](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530) when you do so.

---

<div class="post-metadata">

### Author: ![jandehaan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jandehaan/32/6805_2.png) [@jandehaan](https://discourse.julialang.org/u/jandehaan)
#### Post date: [July 31, 2018, 12:17am UTC](https://discourse.julialang.org/t/dimensionmismatch-a-has-dimensions-1-0-but-b-has-dimensions-5-how-to-eliminate-this-error/12741/5 "2018-07-31T00:17:32Z")

</div>

@RaquelSantos

````julia
# it will look better when you start your code example with ```julia
for i=1: size(TabelaRecursos, 1)
    TipoRecursos = newTabelaRecursos[i]
    Dr = newTabelaRecursos[i,2]
    k =0
    Aux = Array{Any}(0)
    for j = 1: size(newTabelaProdutos_Recursos, 1)
        if newTabelaProdutos_Recursos[j, 2] == TipoRecursos
            k = k +1
            insert!(Aux, k, newTabelaProdutos_Recursos[j, 3])
        end
    end
    Drp = transpose(Aux)
    @constraint(myModel, Drp*Qp &lt;= Dr) # the following error appears on this line:
    DimensionMismatch(“A has dimensions (1, 0) but B has dimensions (5,)”)
end
# and end it with ```

````

---

<div class="post-metadata">

### Author: ![mohamed82008](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mohamed82008/32/18171_2.png) [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)
#### Post date: [July 31, 2018, 12:50am UTC](https://discourse.julialang.org/t/dimensionmismatch-a-has-dimensions-1-0-but-b-has-dimensions-5-how-to-eliminate-this-error/12741/6 "2018-07-31T00:50:59Z")

</div>

> [@ggggggggg](#):
>
> copy and pasteable example

This is what I am getting when I copy and paste your code:

```julia
julia> using JuMP

julia> for i=1:size(TabelaRecursos, 1)
           TipoRecursos = newTabelaRecursos[i]
           Dr = newTabelaRecursos[i,2]
           k =0
           Aux = Array{Any}(0)
           for j = 1: size(newTabelaProdutos_Recursos, 1)
               if newTabelaProdutos_Recursos[j, 2] == TipoRecursos
                   k = k +1
                   insert!(Aux, k, newTabelaProdutos_Recursos[j, 3])
               end
           end
           Drp = transpose(Aux)
           @constraint(myModel, Drp*Qp &lt;= Dr) # the following error appears on this line:
       end
ERROR: syntax: unexpected "="

```

You probably mean `<=` in place of `&lt;=`. Even after fixing that, the variables are not defined so I cannot properly debug the code. So it is not that people don’t want to help, it’s just that you have to start by helping them help you.

---

<div class="post-metadata">

### Author: ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)
#### Post date: [July 31, 2018, 1:07pm UTC](https://discourse.julialang.org/t/dimensionmismatch-a-has-dimensions-1-0-but-b-has-dimensions-5-how-to-eliminate-this-error/12741/9 "2018-07-31T13:07:48Z")

</div>

As mentioned before, it would be really helpful if you could preface wrap code blocks with ````` to turn them into properly formatted code.

Also, I’m assuming it’ll still be hard for people to help given that your code depends on data read in locally on your machine, and therefore is not the [minimal, complete, and verifiable example](https://stackoverflow.com/help/mcve) necessary to actually reproduce and debug your problem.

That said it looks likely that your error comes from a multiplication of to incompatible matrices, so you should probably go through your code step by step to try and understand why the dimensions of `A` and `B` are what they are and what dimensions they should have for your calculations to work.

---

<div class="post-metadata">

### Author: ![RaquelSantos](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/raquelsantos/32/3668_2.png) [@RaquelSantos](https://discourse.julialang.org/u/RaquelSantos)
#### Post date: [July 31, 2018, 1:14pm UTC](https://discourse.julialang.org/t/dimensionmismatch-a-has-dimensions-1-0-but-b-has-dimensions-5-how-to-eliminate-this-error/12741/11 "2018-07-31T13:14:51Z")

</div>

Ok, thank you.
