# BoundsError: attempt to access 5×100 Array{Float32,2} at index \[\[0, 5, … 490, 495\]\]

**URL:** <https://discourse.julialang.org/t/boundserror-attempt-to-access-5x100-array-float32-2-at-index-0-5-490-495/17809>\
**Category:** General Usage\
**Tags:** question\
**Created:** [November 21, 2018, 11:20am UTC](https://discourse.julialang.org/t/boundserror-attempt-to-access-5x100-array-float32-2-at-index-0-5-490-495/17809 "2018-11-21T11:20:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lannisite110](https://avatars.discourse-cdn.com/v4/letter/l/df705f/32.png) [@lannisite110](https://discourse.julialang.org/u/lannisite110)\
**Post date:** [November 21, 2018, 11:20am UTC](https://discourse.julialang.org/t/boundserror-attempt-to-access-5x100-array-float32-2-at-index-0-5-490-495/17809/1 "2018-11-21T11:20:40Z")

</div>

function init\_wb(in\_out=[4096,5])  
w=[xavier(Float32,(in\_out[2],in\_out[1])),zeros(Float32,in\_out[2])]  
end

predict(w,x)=w[1]\*mat(x).+w[2]  
loss(w,x,ygold)=nll(predict(w,x),ygold)  
lossgradient=grad(loss)

julia\> w[1]  
5×4096 Array{Float32,2}:  
0.022014 0.0192639 0.00160997 … 0.027218 0.00113881  
-0.0140597 -0.0636935 -0.00497378 -0.00697153 -0.0373464  
0.0818167 0.0728172 0.013256 0.0259867 0.0501119  
-0.118777 -0.0914147 -0.00677145 -0.0326031 -0.0659944  
0.0523701 0.0537148 0.0220276 0.00529148 0.00907731

julia\> y  
100-element Array{UInt8,1}:  
0x00  
0x00  
0x00  
0x00  
0x00  
0x00  
0x00  
0x00  
0x00  
0x00  
⋮

julia\> x  
1×1×4096×100 Array{Float32,4}:  
[:, :, 1, 1] =  
2.3000634

[:, :, 2, 1] =  
2.5095005

[:, :, 3, 1] =  
0.0

…  
julia\> st=w[1]\*mat(x)  
5×100 Array{Float32,2}:  
405.496 357.088 389.276 321.994 … 476.868 406.444 482.75  
-232.119 -203.723 -228.6 -187.018 -245.119 -219.343 -252.767  
444.043 397.126 435.921 374.369 511.754 441.204 520.46  
-854.678 -760.229 -831.479 -704.527 -1040.34 -882.174 -1049.85  
249.883 221.303 246.57 208.232 300.835 257.746 304.266

julia\> st.+=w[2]  
5×100 Array{Float32,2}:  
405.51 357.103 389.291 322.009 … 476.882 406.458 482.765  
-232.127 -203.731 -228.609 -187.027 -245.128 -219.351 -252.776  
444.064 397.148 435.943 374.391 511.776 441.226 520.482  
-854.716 -760.267 -831.517 -704.565 -1040.38 -882.212 -1049.89  
249.893 221.314 246.58 208.242 300.845 257.757 304.276

julia\> loss(w,x,ygold) = nll(predict(w,x),ygold;dims=1);

julia\> lo=loss(w,x,y)  
ERROR: BoundsError: attempt to access 5×100 Array{Float32,2} at index [[0, 5, 10, 15, 20, 25, 30, 35, 40, 45 … 450, 455, 460, 465, 470, 475, 480, 485, 490, 495]]  
Stacktrace:  
[1] throw\_boundserror(::Array{Float32,2}, ::Tuple{Array{Int64,1}}) at ./abstractarray.jl:484  
[2] checkbounds at ./abstractarray.jl:449 [inlined]  
[3] \_getindex at ./multidimensional.jl:588 [inlined]  
[4] getindex at ./abstractarray.jl:905 [inlined]  
[5] #nll#599(::Int64, ::Bool, ::Function, ::Array{Float32,2}, ::Array{UInt8,1}) at /home/users/xdlan/.julia/packages/Knet/rKugL/src/loss.jl:219  
[6] (::getfield(Knet, Symbol(“#kw##nll”)))(::NamedTuple{(:dims,),Tuple{Int64}}, ::typeof(nll), ::Array{Float32,2}, ::Array{UInt8,1}) at ./none:0  
[7] loss(::Array{Array{Float32,N} where N,1}, ::Array{Float32,4}, ::Array{UInt8,1}) at ./REPL[74]:1  
[8] top-level scope at none:0

---

<div class="post-metadata">

**Author:** ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)\
**Post date:** [November 21, 2018, 11:30am UTC](https://discourse.julialang.org/t/boundserror-attempt-to-access-5x100-array-float32-2-at-index-0-5-490-495/17809/2 "2018-11-21T11:30:37Z")

</div>

> [@Please read: make it easier to help you](https://discourse.julialang.org/t/psa-make-it-easier-to-help-you/14757):
>
> Welcome to the Julia Discourse! We are enthusiastic about helping Julia programmers, both beginner and experienced. This public service announcement (PSA) outlines best practices when asking for help. Following these points makes it easier for us to help you and more likely you’ll get a prompt, useful answer. Keywords are highlighted to make it easier to refer to specific points. Choose a descriptive title that captures the key part of your question, eg “plots with multiple axes” instead of …

---

<div class="post-metadata">

**Author:** ![y4lu](https://avatars.discourse-cdn.com/v4/letter/y/47e85d/32.png) [@y4lu](https://discourse.julialang.org/u/y4lu)\
**Post date:** [November 21, 2018, 11:54am UTC](https://discourse.julialang.org/t/boundserror-attempt-to-access-5x100-array-float32-2-at-index-0-5-490-495/17809/3 "2018-11-21T11:54:51Z")

</div>

There’s no index 0 by default in standard julia arrays and vectors, did you make a `0:5:495` vector somewhere?

---

<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:** [November 21, 2018, 2:29pm UTC](https://discourse.julialang.org/t/boundserror-attempt-to-access-5x100-array-float32-2-at-index-0-5-490-495/17809/4 "2018-11-21T14:29:43Z")

</div>

Building on Sukera’s point, you have been posting quite a few similar questions over the past weeks (no MWE, code not quoted, unclear or no question, titles that are unclear or simple error messages).

On most of these threads, you’ve been advised to post MWEs, quote your code, and clearly set out your questions - I think people would appreciate if you could consider this repeated advise (and you would probably benefit as you’d make it easier for others to help you!)
