# \#indexing

**URL:** https://discourse.julialang.org/tag/indexing/102.md

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

---

## [Where is the lowering of end within \[ \] documented](https://discourse.julialang.org/t/where-is-the-lowering-of-end-within-documented/136736)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 7\
**Last updated:** [April 18, 2026, 9:23am UTC](https://discourse.julialang.org/t/where-is-the-lowering-of-end-within-documented/136736 "2026-04-18T09:23:33Z")

</div>

Where is the lowering of end within \[\] documented? Ie the fact that it is assigned a value from lastindex, as in julia\> Meta.@lower (1:4)\[min(end, 5)\] :($(Expr(:thunk, CodeInfo( 1 ─ %1 = Main.:(:) │ %2 = dynamic (%1…

---

## [Improve performance of this index creation and accessing code](https://discourse.julialang.org/t/improve-performance-of-this-index-creation-and-accessing-code/134235)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 65\
**Last updated:** [January 30, 2026, 3:47pm UTC](https://discourse.julialang.org/t/improve-performance-of-this-index-creation-and-accessing-code/134235 "2026-01-30T15:47:32Z")

</div>

How to improve the performance of clp(j) function given below. Please suggest faster version of this code. I am converting spherical coordinates to Cartesian and placing color values to exact location in data. Otherwise…

---

## [Using BitArray to index into another Array](https://discourse.julialang.org/t/using-bitarray-to-index-into-another-array/43205)

<div class="topic-metadata">

**Author:** [@a.fas](https://discourse.julialang.org/u/a.fas)\
**Replies:** 10\
**Last updated:** [January 27, 2026, 5:14am UTC](https://discourse.julialang.org/t/using-bitarray-to-index-into-another-array/43205 "2026-01-27T05:14:13Z")

</div>

Hello, I am confused by the error I receive on a simple piece of code involving a BitArray. Here is a MWE: a = \[1 2 3\]; B = \[1 2 3; 4 5 6; 7 8 9\]; ids = all(a. == B, dims=2); Everything works as intended up to here and…

---

## [Multi-dimensional indices are incompatible with \`end\` index](https://discourse.julialang.org/t/multi-dimensional-indices-are-incompatible-with-end-index/134886)

<div class="topic-metadata">

**Author:** [@aryavorskiy](https://discourse.julialang.org/u/aryavorskiy)\
**Replies:** 1\
**Last updated:** [January 5, 2026, 2:14pm UTC](https://discourse.julialang.org/t/multi-dimensional-indices-are-incompatible-with-end-index/134886 "2026-01-05T14:14:41Z")

</div>

Julia allows to access the last index in the axis of an array using the end keyword by lowering it to lastindex in a rather predictable way: A = rand(5, 5, 2) A\[1:end - 1, end ÷ 2, :\] # lowers to A\[1:lastindex(A, 1) - 1…

---

## [Shorthand for ((i-1)\*k+1):(i\*k)](https://discourse.julialang.org/t/shorthand-for-i-1-k-1-i-k/133968)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 5\
**Last updated:** [November 18, 2025, 2:49pm UTC](https://discourse.julialang.org/t/shorthand-for-i-1-k-1-i-k/133968 "2025-11-18T14:49:35Z")

</div>

I often run into the problem of partitioning data to into equal “chunks”, eg a vector of N\*K elements into N chunks of K, then doing something to each chunk. As an MWE, consider z = zeros(N\*K) for i in 1:N z\[((i-1)\*…

---

## [Slicing a matrix of matrices](https://discourse.julialang.org/t/slicing-a-matrix-of-matrices/131161)

<div class="topic-metadata">

**Author:** [@tduretz](https://discourse.julialang.org/u/tduretz)\
**Replies:** 5\
**Last updated:** [July 30, 2025, 7:29am UTC](https://discourse.julialang.org/t/slicing-a-matrix-of-matrices/131161 "2025-07-30T07:29:52Z")

</div>

I would like to better understand how to slice matrices of matrices. For example, I initialise a matrix of matrices this way: M = \[\[1 0; 0 2\] for i = 1:2, j=1:2\] If I slice it this way: M\[1,1\]\[:,:\] I obtain the result…

---

## [Indexing by names, current favorites in the package space](https://discourse.julialang.org/t/indexing-by-names-current-favorites-in-the-package-space/123097)

<div class="topic-metadata">

**Author:** [@cdawg](https://discourse.julialang.org/u/cdawg)\
**Replies:** 7\
**Last updated:** [June 6, 2025, 8:40pm UTC](https://discourse.julialang.org/t/indexing-by-names-current-favorites-in-the-package-space/123097 "2025-06-06T20:40:18Z")

</div>

I loved AxisArrays.jl. However AxisArrays is old (designed pre1.0). It still works…ok, but I miss broadcasting and Not-.indexing. I did not learn about its newer counterparts until I had written a few weeks of analysis a…

---

## [\`\`mod1\`\` based Periodic Indexing on GPUs](https://discourse.julialang.org/t/mod1-based-periodic-indexing-on-gpus/128657)

<div class="topic-metadata">

**Author:** [@bpsomu](https://discourse.julialang.org/u/bpsomu)\
**Replies:** 1\
**Last updated:** [May 3, 2025, 5:27pm UTC](https://discourse.julialang.org/t/mod1-based-periodic-indexing-on-gpus/128657 "2025-05-03T17:27:42Z")

</div>

I am using the following approach to apply boundary conditions using mod1 for my Simulation code, that I want to be performant on GPUs: struct DirichletArray{arr\<:AbstractArray, T} data::arr core\_boundary\_value:…

---

## [Find indexes of a String in Multi -Type Matrix](https://discourse.julialang.org/t/find-indexes-of-a-string-in-multi-type-matrix/128072)

<div class="topic-metadata">

**Author:** [@Vasilis\_Dim](https://discourse.julialang.org/u/Vasilis_Dim)\
**Replies:** 2\
**Last updated:** [April 14, 2025, 7:20pm UTC](https://discourse.julialang.org/t/find-indexes-of-a-string-in-multi-type-matrix/128072 "2025-04-14T19:20:36Z")

</div>

Hello There! I have created a matrix such as: T=Union{String, Int} June=Matrix{T}(undef,10,30) Later in the code some entries of A might change to a string (let’s say “Bill”). I tried to locate the indexes where that’…

---

## [Abstract type for 1-indexed Arrays](https://discourse.julialang.org/t/abstract-type-for-1-indexed-arrays/127240)

<div class="topic-metadata">

**Author:** [@leespen1](https://discourse.julialang.org/u/leespen1)\
**Replies:** 4\
**Last updated:** [March 21, 2025, 9:39pm UTC](https://discourse.julialang.org/t/abstract-type-for-1-indexed-arrays/127240 "2025-03-21T21:39:36Z")

</div>

Is there an abstract type that includes only absract arrays which have “standard” indexing, by which I mean the first valid index along each axis is 1, and the last valid index along the i-th axis of A is size(A, i)? I …

---

## [How to select elements of a three-dimensional array fast](https://discourse.julialang.org/t/how-to-select-elements-of-a-three-dimensional-array-fast/127185)

<div class="topic-metadata">

**Author:** [@Joris\_Pinkse](https://discourse.julialang.org/u/Joris_Pinkse)\
**Replies:** 4\
**Last updated:** [March 20, 2025, 10:28pm UTC](https://discourse.julialang.org/t/how-to-select-elements-of-a-three-dimensional-array-fast/127185 "2025-03-20T22:28:50Z")

</div>

I have large three-dimensional arrays A that have different values, but from which I always wish to select the same set of entries. So A is a different matrix each time, but it has the same size and I need to collect th…

---

## [Select specific elements from each column of a matrix in julia](https://discourse.julialang.org/t/select-specific-elements-from-each-column-of-a-matrix-in-julia/127138)

<div class="topic-metadata">

**Author:** [@alex180500](https://discourse.julialang.org/u/alex180500)\
**Replies:** 4\
**Last updated:** [March 19, 2025, 6:24pm UTC](https://discourse.julialang.org/t/select-specific-elements-from-each-column-of-a-matrix-in-julia/127138 "2025-03-19T18:24:16Z")

</div>

Let’s say I have this 16x1000 matrix: test\_mat = rand(16, 1000) And I have these indices: test\_indices = rand(1:16, 4, 1000) I want to extract from test\_mat a 4x1000 matrix where the indices of the row are represente…

---

## [Keep array elements that are NOT in a list of indexes](https://discourse.julialang.org/t/keep-array-elements-that-are-not-in-a-list-of-indexes/125555)

<div class="topic-metadata">

**Author:** [@JM\_Beckers](https://discourse.julialang.org/u/JM_Beckers)\
**Replies:** 8\
**Last updated:** [February 5, 2025, 12:40pm UTC](https://discourse.julialang.org/t/keep-array-elements-that-are-not-in-a-list-of-indexes/125555 "2025-02-05T12:40:55Z")

</div>

Suppose I have a list of indexes mylist, is there an equivalent of setdiff(myarray, myarray\[mylist\]) but using directly the fact that I know which elements are to the eliminated (through mylist) in order to be more ef…

---

## [Elegant way of exclusive indexing](https://discourse.julialang.org/t/elegant-way-of-exclusive-indexing/76894)

<div class="topic-metadata">

**Author:** [@TheLateKronos](https://discourse.julialang.org/u/TheLateKronos)\
**Replies:** 41\
**Last updated:** [February 26, 2022, 4:34pm UTC](https://discourse.julialang.org/t/elegant-way-of-exclusive-indexing/76894 "2022-02-26T16:34:17Z")

</div>

In R, you can index all elements except for the second, by negative indexing: myvector\[-2\]. This is especially usefull if you want to make two complete subsets of a vector: set1 = myvector\[inds\] set2 = myvector\[-inds\] W…

---

## [How do I find the number of bytes for a character?](https://discourse.julialang.org/t/how-do-i-find-the-number-of-bytes-for-a-character/124144)

<div class="topic-metadata">

**Author:** [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Replies:** 3\
**Last updated:** [December 24, 2024, 4:48pm UTC](https://discourse.julialang.org/t/how-do-i-find-the-number-of-bytes-for-a-character/124144 "2024-12-24T16:48:46Z")

</div>

Hello, Please take a look at the following text: Consider the following: julia\> grk = “β+θ” “β+θ” julia\> length(grk) 3 julia\> sizeof(grk) 5 Since β and θ occupy two bytes each, the valid indices into grk are 1 …

---

## [A question about SubString](https://discourse.julialang.org/t/a-question-about-substring/123838)

<div class="topic-metadata">

**Author:** [@hack3rcon](https://discourse.julialang.org/u/hack3rcon)\
**Replies:** 8\
**Last updated:** [December 15, 2024, 8:21am UTC](https://discourse.julialang.org/t/a-question-about-substring/123838 "2024-12-15T08:21:55Z")

</div>

Hello, What is the difference between SubString and Indexing? I did: julia\> str = "Where the mind is without fear" "Where the mind is without fear" julia\> SubString(str, 1, 5) "Where" julia\> str\[1:5\] "Where" The res…

---

## [Is there a non-allocating version of findall?](https://discourse.julialang.org/t/is-there-a-non-allocating-version-of-findall/120832)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 1\
**Last updated:** [October 2, 2024, 11:47pm UTC](https://discourse.julialang.org/t/is-there-a-non-allocating-version-of-findall/120832 "2024-10-02T23:47:00Z")

</div>

MWEusing StaticArrays, BenchmarkTools # Data vector dat = collect(1:10); # Always five "trues" but at any indices flag = \[trues(3); falses(5); trues(2)\]; # Index with vector of bools @btime ($dat\[$flag\]); @b…

---

## ["Raster" syntax in GeoStats.jl](https://discourse.julialang.org/t/raster-syntax-in-geostats-jl/119214)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 0\
**Last updated:** [September 9, 2024, 11:07am UTC](https://discourse.julialang.org/t/raster-syntax-in-geostats-jl/119214 "2024-09-09T11:07:09Z")

</div>

Given that most people in the geo community are not aware of the “raster” syntax in GeoStats.jl, I collect a few examples here to facilitate the transition. This post may become part of the official project documentation…

---

## [Pick the value from a result](https://discourse.julialang.org/t/pick-the-value-from-a-result/118713)

<div class="topic-metadata">

**Author:** [@Stephen](https://discourse.julialang.org/u/Stephen)\
**Replies:** 1\
**Last updated:** [August 29, 2024, 8:36am UTC](https://discourse.julialang.org/t/pick-the-value-from-a-result/118713 "2024-08-29T08:36:46Z")

</div>

Here is a solution of a Bayesian inference using RxInfer: julia\> result Inference results: Posteriors | available for (i\_β) julia\> result.posteriors Dict{Symbol, Vector{Dirichlet{Float64, Vector{Float64}, Float…

---

## [Indexing array with a matrix and scalar](https://discourse.julialang.org/t/indexing-array-with-a-matrix-and-scalar/116848)

<div class="topic-metadata">

**Author:** [@baptnz](https://discourse.julialang.org/u/baptnz)\
**Replies:** 9\
**Last updated:** [July 10, 2024, 7:33pm UTC](https://discourse.julialang.org/t/indexing-array-with-a-matrix-and-scalar/116848 "2024-07-10T19:33:45Z")

</div>

A bit rusty after a while away from julia… How would I fill a 3D array with N values at positions given as follows: 1st index given as a scalar (from a for loop) the other two indices are provided as vectors I’m u…

---

## [Inconsistent pool and invpool PooledArrays](https://discourse.julialang.org/t/inconsistent-pool-and-invpool-pooledarrays/116828)

<div class="topic-metadata">

**Author:** [@SamTheGeneticCoder](https://discourse.julialang.org/u/SamTheGeneticCoder)\
**Replies:** 0\
**Last updated:** [July 9, 2024, 1:58pm UTC](https://discourse.julialang.org/t/inconsistent-pool-and-invpool-pooledarrays/116828 "2024-07-09T13:58:16Z")

</div>

Hi there! Could someone help me understand the “inconsistent pool and invpool” error in PooledArrays.jl? Thanks in advance!

---

## [Using subscript to index an array](https://discourse.julialang.org/t/using-subscript-to-index-an-array/115190)

<div class="topic-metadata">

**Author:** [@bsuwal](https://discourse.julialang.org/u/bsuwal)\
**Replies:** 4\
**Last updated:** [June 4, 2024, 7:34pm UTC](https://discourse.julialang.org/t/using-subscript-to-index-an-array/115190 "2024-06-04T19:34:05Z")

</div>

Is there any macro or functionality that would allow me to index the elements of an array by subscript? For eg if I had an array: A = \[1, 2, 3\] I would like to have code such as: for i=1:length(A) A\\\_i = A\\\_i \* 3…

---

## [Is there a \`CartesianIndex\` using \`Int32\`?](https://discourse.julialang.org/t/is-there-a-cartesianindex-using-int32/114468)

<div class="topic-metadata">

**Author:** [@SteffenPL](https://discourse.julialang.org/u/SteffenPL)\
**Replies:** 8\
**Last updated:** [May 20, 2024, 12:18pm UTC](https://discourse.julialang.org/t/is-there-a-cartesianindex-using-int32/114468 "2024-05-20T12:18:15Z")

</div>

The definition in Julia base/multidimensional.jl is restricted to Int64 struct CartesianIndex{N} \<: AbstractCartesianIndex{N} I::NTuple{N,Int} CartesianIndex{N}(index::NTuple{N,Integer}) where {N} = new(in…

---

## [Replacing components with indices](https://discourse.julialang.org/t/replacing-components-with-indices/113412)

<div class="topic-metadata">

**Author:** [@KeepLearning](https://discourse.julialang.org/u/KeepLearning)\
**Replies:** 12\
**Last updated:** [April 25, 2024, 4:00pm UTC](https://discourse.julialang.org/t/replacing-components-with-indices/113412 "2024-04-25T16:00:55Z")

</div>

I am wondering if the following can be done in a better way (without for loop, perhaps): given a vector and a vector of vectors, e.g. v = \[1, 2, 3, 3, 4, 4, 5\] u = \[\[1,2\], \[3, 5\], \[4\]\] I like to get \[1, 1, 2, 2, 3, 3,…

---

## [Apparently \`getindex\` of a vector accepts more than one index?!](https://discourse.julialang.org/t/apparently-getindex-of-a-vector-accepts-more-than-one-index/113302)

<div class="topic-metadata">

**Author:** [@nsajko](https://discourse.julialang.org/u/nsajko)\
**Replies:** 1\
**Last updated:** [April 21, 2024, 12:06pm UTC](https://discourse.julialang.org/t/apparently-getindex-of-a-vector-accepts-more-than-one-index/113302 "2024-04-21T12:06:59Z")

</div>

Why doesn’t this throw, given that the array \[10, 20\] is one-dimensional? I would expect a MethodError. julia\> \[10, 20\]\[1, 1, 1\] 10

---

## [Indexable set data structure](https://discourse.julialang.org/t/indexable-set-data-structure/112287)

<div class="topic-metadata">

**Author:** [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Replies:** 8\
**Last updated:** [April 2, 2024, 9:25am UTC](https://discourse.julialang.org/t/indexable-set-data-structure/112287 "2024-04-02T09:25:12Z")

</div>

I’m looking for a data structure that I’m sure must have already been invented and implemented, but which I can’t find (probably because I don’t know its canonical name). The data structure I have in mind shares some pr…

---

## [ANN: StringUnits.jl](https://discourse.julialang.org/t/ann-stringunits-jl/112202)

<div class="topic-metadata">

**Author:** [@mnemnion](https://discourse.julialang.org/u/mnemnion)\
**Replies:** 8\
**Last updated:** [March 28, 2024, 5:28pm UTC](https://discourse.julialang.org/t/ann-stringunits-jl/112202 "2024-03-28T17:28:00Z")

</div>

Inspired by this lengthy thread, which I jumped into somewhat later, I’ve implemented the idea as StringUnits.jl. Pretty straightforward: julia\> "aβc∅👨🏻‍🌾efg"\[2ch:4ch\] "βc∅" julia\> "aβc∅👨🏻‍🌾efg"\[5gr\] "👨🏻‍🌾" julia\> "a…

---

## [StringIndex idea (Julia 2.0)](https://discourse.julialang.org/t/stringindex-idea-julia-2-0/107185)

<div class="topic-metadata">

**Author:** [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Replies:** 71\
**Last updated:** [March 27, 2024, 10:11pm UTC](https://discourse.julialang.org/t/stringindex-idea-julia-2-0/107185 "2024-03-27T22:11:11Z")

</div>

Continuing the discussion from String indices : byte indexing feels wrong… The other day I had a somewhat clever idea for how to preserve the O(1) indexing benefits that Julia currently has, while making string indexing …

---

## [Add specific elements of a CUDA matrix](https://discourse.julialang.org/t/add-specific-elements-of-a-cuda-matrix/111909)

<div class="topic-metadata">

**Author:** [@NonDairyNeutrino](https://discourse.julialang.org/u/NonDairyNeutrino)\
**Replies:** 1\
**Last updated:** [March 21, 2024, 2:48pm UTC](https://discourse.julialang.org/t/add-specific-elements-of-a-cuda-matrix/111909 "2024-03-21T14:48:48Z")

</div>

Question I have an N \\times N matrix A on the GPU (e.g. CuArray{Float32, 2, CUDA.Mem.DeviceBuffer} from CUDA.jl), and two N-element “index vectors” iVector and jVector also on the GPU. I want to add the elements of A lo…

---

## [\[ANN\] FFTIndexing.jl](https://discourse.julialang.org/t/ann-fftindexing-jl/111433)

<div class="topic-metadata">

**Author:** [@brainandforce](https://discourse.julialang.org/u/brainandforce)\
**Replies:** 0\
**Last updated:** [March 10, 2024, 9:23pm UTC](https://discourse.julialang.org/t/ann-fftindexing-jl/111433 "2024-03-10T21:23:52Z")

</div>

FFTIndexing.jl is a small package I’ve written that provides a few types that you can use to index an array in a manner that exposes the underlying frequency bins from a Fourier transform. This package accomplishes simi…

[Next page](https://discourse.julialang.org/tag/indexing/102.md?match_all_tags=true&page=1&tags%5B%5D=indexing)
