# Indexed assignment with logical indices: subarray.jl error

**URL:** <https://discourse.julialang.org/t/indexed-assignment-with-logical-indices-subarray-jl-error/83646>\
**Category:** New to Julia\
**Tags:** indexing\
**Created:** [July 1, 2022, 10:03pm UTC](https://discourse.julialang.org/t/indexed-assignment-with-logical-indices-subarray-jl-error/83646 "2022-07-01T22:03:40Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bast](https://avatars.discourse-cdn.com/v4/letter/b/3e96dc/32.png) [@bast](https://discourse.julialang.org/u/bast)\
**Post date:** [July 1, 2022, 10:03pm UTC](https://discourse.julialang.org/t/indexed-assignment-with-logical-indices-subarray-jl-error/83646/1 "2022-07-01T22:03:40Z")

</div>

Hi,

I have run into an error that I do not quite understand:

I have a BitArray whose entries I want to change based on another array

```julia
A = BitArray(rand(0:1, 3,3))
pos = randn(3,3)
A[pos .< 0] .= 0

```

This yields the error message:

> ERROR: ArgumentError: number of indices (1) must match the parent dimensionality (2)  
> Stacktrace:  
> [1] check\_parent\_index\_match(parent::BitMatrix, #unused#::Tuple{Bool})  
> @ Base ./subarray.jl:43  
> [2] check\_parent\_index\_match(parent::BitMatrix, indices::Tuple{Vector{Int64}})  
> @ Base ./subarray.jl:41  
> [3] SubArray  
> @ ./subarray.jl:21 [inlined]  
> [4] SubArray  
> @ ./subarray.jl:32 [inlined]  
> [5] SubArray  
> @ ./subarray.jl:28 [inlined]  
> [6] materialize!(B::Base.Broadcast.BitMaskedBitArray{2, 2}, bc::Base.Broadcast.Broadcasted{Base.Broadcast.DefaultArrayStyle{0}, Nothing, typeof(identity), Tuple{Int64}})  
> @ Base.Broadcast ./broadcast.jl:1174  
> [7] top-level scope  
> @ REPL[10]:1

The indexing works without an error, the error only appears when I try to assign the new value.

Thank you for any ideas!

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 1, 2022, 10:09pm UTC](https://discourse.julialang.org/t/indexed-assignment-with-logical-indices-subarray-jl-error/83646/2 "2022-07-01T22:09:14Z")

</div>

This is a bug. Could you [open an issue](https://github.com/JuliaLang/julia/issues/new) please?

---

<div class="post-metadata">

**Author:** ![bast](https://avatars.discourse-cdn.com/v4/letter/b/3e96dc/32.png) [@bast](https://discourse.julialang.org/u/bast)\
**Post date:** [July 1, 2022, 10:10pm UTC](https://discourse.julialang.org/t/indexed-assignment-with-logical-indices-subarray-jl-error/83646/3 "2022-07-01T22:10:23Z")

</div>

Okay, thank you for the quick reply - will do!

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [July 1, 2022, 10:24pm UTC](https://discourse.julialang.org/t/indexed-assignment-with-logical-indices-subarray-jl-error/83646/4 "2022-07-01T22:24:02Z")

</div>

Thanks! Ref [#45903](https://github.com/JuliaLang/julia/issues/45903) and [#45904](https://github.com/JuliaLang/julia/issues/45904).
