# DimensionMismatch("tried to assign 15-element array to 1×5 destination")

**URL:** <https://discourse.julialang.org/t/dimensionmismatch-tried-to-assign-15-element-array-to-1x5-destination/90167>\
**Category:** New to Julia\
**Tags:** question\
**Created:** [November 12, 2022, 7:19pm UTC](https://discourse.julialang.org/t/dimensionmismatch-tried-to-assign-15-element-array-to-1x5-destination/90167 "2022-11-12T19:19:26Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Eric.O](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@Eric.O](https://discourse.julialang.org/u/Eric.O)\
**Post date:** [November 12, 2022, 7:19pm UTC](https://discourse.julialang.org/t/dimensionmismatch-tried-to-assign-15-element-array-to-1x5-destination/90167/1 "2022-11-12T19:19:26Z")

</div>

I keep struggling to correct this error in my code “DimensionMismatch(“tried to assign 15-element array to 1×5 destination”)”. I kindly need help to correct this code to get it running correctly please. Thank you. My code is attached

```julia

a1=[0, 2.5, -2.5, 2, -2.5] # x cordinates of the circle
b1=[0, 0.3, 0.25, -2.5, -2.25] # y cordinates of the circle

r1= [2, 2 , 2 , 2 ,2] # Radiuus of circle
A=[1 0 0 0 1;0 0 0 1 1;1 0 0 0 1;0 0 1 1 1;0 0 0 1 1; 0 1 0 0 1;0 0 1 1 0;0 0 0 1 0;
   1 0 0 0 0;1 1 0 0 0;0 1 0 0 0;0 0 1 0 0;0 0 1 0 0;1 0 0 0 0;0 0 0 1 0 ]  
m,n=size(A)
CoveredItems=zeros(Int64,m)
Coverage=zeros(Int64,n)
for i in 1:n
   sumval=sum(A[:,i])
   Coverage[i]=sumval
end
SelectedSolution=zeros(Int64,n)
maxval,maxpos=findmax(Coverage)
CoveredItems=A[:,maxpos]
SelectedSolution[maxpos]=1
count=maxval
println(maxpos)

UncoveredItems=zeros(Int64,m)
for i in 1:m
   if (CoveredItems[i]==0)
       UncoveredItems[i]=1
   else
      A[i,:]=zeros(Int64,m) 
   end
end

print(A)

```

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [November 12, 2022, 7:29pm UTC](https://discourse.julialang.org/t/dimensionmismatch-tried-to-assign-15-element-array-to-1x5-destination/90167/2 "2022-11-12T19:29:59Z")

</div>

The problem is this line:

```julia
A[i,:] = zeros(Int64,m) 

```

The left side has the dimension 1x5 while the right side has 15 elements.

---

<div class="post-metadata">

**Author:** ![Eric.O](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@Eric.O](https://discourse.julialang.org/u/Eric.O)\
**Post date:** [November 12, 2022, 8:08pm UTC](https://discourse.julialang.org/t/dimensionmismatch-tried-to-assign-15-element-array-to-1x5-destination/90167/3 "2022-11-12T20:08:21Z")

</div>

Can you please suggest what I do to correct this?  
I am quite confused here.

---

<div class="post-metadata">

**Author:** ![jacobusmmsmit](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jacobusmmsmit/32/217669_2.png) [@jacobusmmsmit](https://discourse.julialang.org/u/jacobusmmsmit)\
**Post date:** [November 12, 2022, 8:12pm UTC](https://discourse.julialang.org/t/dimensionmismatch-tried-to-assign-15-element-array-to-1x5-destination/90167/4 "2022-11-12T20:12:40Z")

</div>

I think you need to swap the `m` for an `n` i.e.

```julia
A[i,:]=zeros(Int64, n)

```

You could also write this as

```julia
A[i, :] .= 0

```

and this would have better performance as `zeros(Int64, n)` allocates a vector every single time you call it.

---

<div class="post-metadata">

**Author:** ![Eric.O](https://avatars.discourse-cdn.com/v4/letter/e/9dc877/32.png) [@Eric.O](https://discourse.julialang.org/u/Eric.O)\
**Post date:** [November 12, 2022, 8:16pm UTC](https://discourse.julialang.org/t/dimensionmismatch-tried-to-assign-15-element-array-to-1x5-destination/90167/5 "2022-11-12T20:16:33Z")

</div>

Thank you very much. This works now.  
Highly Appreciated, please.
