# Find indices or corresponding values except given indices

**URL:** <https://discourse.julialang.org/t/find-indices-or-corresponding-values-except-given-indices/72637>\
**Category:** New to Julia\
**Tags:** indexing\
**Created:** [December 6, 2021, 9:25am UTC](https://discourse.julialang.org/t/find-indices-or-corresponding-values-except-given-indices/72637 "2021-12-06T09:25:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![iHany](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihany/32/18151_2.png) [@iHany](https://discourse.julialang.org/u/iHany)\
**Post date:** [December 6, 2021, 9:25am UTC](https://discourse.julialang.org/t/find-indices-or-corresponding-values-except-given-indices/72637/1 "2021-12-06T09:25:51Z")

</div>

Hi,  
I’d like to know how to access the rest except for given indices.  
For example,

```julia
A = [1 2; 3 4] # 2 x 2
indices = findall(a -> a == 1, A) # indices = [CartesianIndex(1, 1)]
# _indices = [CartesianIndex(2, 1), CartesianIndex(1, 2), CartesianIndex(2, 2)]

```

Of course, not using `findall(a -> a != 1, A)`. Instead, a function should look like `except(indices, A) = _indices`.

---

<div class="post-metadata">

**Author:** ![iHany](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ihany/32/18151_2.png) [@iHany](https://discourse.julialang.org/u/iHany)\
**Post date:** [December 6, 2021, 9:29am UTC](https://discourse.julialang.org/t/find-indices-or-corresponding-values-except-given-indices/72637/2 "2021-12-06T09:29:06Z")

</div>

In the 1-d case, [this post](https://stackoverflow.com/questions/46417005/exclude-elements-of-array-based-on-index-julia) makes sense, for example,

```julia
julia> A = [1, 2, 3, 4]
4-element Vector{Int64}:
 1
 2
 3
 4

julia> A = -A
4-element Vector{Int64}:
 -1
 -2
 -3
 -4

julia> indices = findall(a -> a == -1, A)
1-element Vector{Int64}:
 1

julia> A[1:end .!= indices]
3-element Vector{Int64}:
 -2
 -3
 -4

```

Actually, my demand is for 1-d array so my issue is resolved.  
BTW, any ideas for n-d arrays?

---

<div class="post-metadata">

**Author:** ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)\
**Post date:** [December 6, 2021, 10:02am UTC](https://discourse.julialang.org/t/find-indices-or-corresponding-values-except-given-indices/72637/3 "2021-12-06T10:02:52Z")

</div>

One way is to work with logical indices, i.e. boolean flags:

```julia
A = [1 2; 3 4]
flags = A .== 1
A[.!flags]

```

Another way is using `Not` from the InvertedIndices package:

```julia
using InvertedIndices
A = [1 2; 3 4]
indices = findall(a -> a == 1, A)
A[Not(indices)]

```
