# \#indexing

**URL:** https://discourse.julialang.org/tag/indexing/102.md?page=1

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

**Page:** 2

---

## [Index a matrix with two separate row and column index vectors](https://discourse.julialang.org/t/index-a-matrix-with-two-separate-row-and-column-index-vectors/110410)

<div class="topic-metadata">

**Author:** [@Shuhua](https://discourse.julialang.org/u/Shuhua)\
**Replies:** 4\
**Last updated:** [February 20, 2024, 8:26am UTC](https://discourse.julialang.org/t/index-a-matrix-with-two-separate-row-and-column-index-vectors/110410 "2024-02-20T08:26:17Z")

</div>

I have a matrix A and a row index vector R and a column index vector C. I want to get a vector from A as \[A\[R\[1\], C\[1\]\], A\[R\[2\], C\[2\]\], ...\]. For instance, with R=\[2, 4\], C=\[3, 1\], I want \[A\[2, 3\], A\[4, 1\]\]. Is there …

---

## [Matching filtered Vector{String} to non-filtered Matrix{Any} - GPS station names](https://discourse.julialang.org/t/matching-filtered-vector-string-to-non-filtered-matrix-any-gps-station-names/110230)

<div class="topic-metadata">

**Author:** [@GeodeticR](https://discourse.julialang.org/u/GeodeticR)\
**Replies:** 9\
**Last updated:** [February 15, 2024, 7:44pm UTC](https://discourse.julialang.org/t/matching-filtered-vector-string-to-non-filtered-matrix-any-gps-station-names/110230 "2024-02-15T19:44:51Z")

</div>

Hello all, I’ve been attempting to match an array of GPS stations names that I’ve filtered such that I have a time frame I’m interested and that the percentage of collection in that time is \> 93%. The issue is, that I …

---

## [Please someone explain me the array indexing example from manual?](https://discourse.julialang.org/t/please-someone-explain-me-the-array-indexing-example-from-manual/110174)

<div class="topic-metadata">

**Author:** [@benibilme](https://discourse.julialang.org/u/benibilme)\
**Replies:** 5\
**Last updated:** [February 14, 2024, 1:48pm UTC](https://discourse.julialang.org/t/please-someone-explain-me-the-array-indexing-example-from-manual/110174 "2024-02-14T13:48:31Z")

</div>

I am truly lost at following example. I appreciate any directions, I seem to understand all previous examples, but this one just made me dazzle. Julia 1.10 manual array indexing section If I\_1 is changed to a two-dime…

---

## [Proposal: function for mutating operators?](https://discourse.julialang.org/t/proposal-function-for-mutating-operators/109707)

<div class="topic-metadata">

**Author:** [@aryavorskiy](https://discourse.julialang.org/u/aryavorskiy)\
**Replies:** 9\
**Last updated:** [February 4, 2024, 10:23pm UTC](https://discourse.julialang.org/t/proposal-function-for-mutating-operators/109707 "2024-02-04T22:23:23Z")

</div>

I want my custom type to implement indexed increments A\[...\] += B, but not assignments A\[...\] = B. Currently, syntax like A\[1:3\] += \[1, 2, 3\] is parsed A\[1:3\] = A\[1:3\] + \[1, 2, 3\]. This is straightforward, but unoptimal…

---

## [Get indices of unique rows in 2D array](https://discourse.julialang.org/t/get-indices-of-unique-rows-in-2d-array/109208)

<div class="topic-metadata">

**Author:** [@dalarev](https://discourse.julialang.org/u/dalarev)\
**Replies:** 12\
**Last updated:** [January 25, 2024, 11:07pm UTC](https://discourse.julialang.org/t/get-indices-of-unique-rows-in-2d-array/109208 "2024-01-25T23:07:04Z")

</div>

MWE: A = \[1 2 ; 3 4 ; 1 2 \] I want as output the row indices 1, 2. Using unique, one can access the indices of unique values by using i = unique(i -\> A\[i\], eachindex(A)), however I don’t know how to modify this for …

---

## [Is there a function for creating n (nearly) evenly-spaced integers for indexing?](https://discourse.julialang.org/t/is-there-a-function-for-creating-n-nearly-evenly-spaced-integers-for-indexing/108744)

<div class="topic-metadata">

**Author:** [@parb](https://discourse.julialang.org/u/parb)\
**Replies:** 35\
**Last updated:** [January 16, 2024, 12:33am UTC](https://discourse.julialang.org/t/is-there-a-function-for-creating-n-nearly-evenly-spaced-integers-for-indexing/108744 "2024-01-16T00:33:09Z")

</div>

Hi all, I’d like to downsample arrays with something like longarray = rand(100) numsamples = 30 sampleindices = evenintegers(1, length(longarray), numsamples) downsampled = longarray\[sampleindices\] I realize its not o…

---

## [How to get the "interior" view of a multidimensional array with unknown number of axes](https://discourse.julialang.org/t/how-to-get-the-interior-view-of-a-multidimensional-array-with-unknown-number-of-axes/107759)

<div class="topic-metadata">

**Author:** [@jinfreedom](https://discourse.julialang.org/u/jinfreedom)\
**Replies:** 1\
**Last updated:** [December 18, 2023, 10:13am UTC](https://discourse.julialang.org/t/how-to-get-the-interior-view-of-a-multidimensional-array-with-unknown-number-of-axes/107759 "2023-12-18T10:13:11Z")

</div>

Hi, I would like to extract “interior” part of an array A\_int=A\[h:end-h,h:end-h,...\] where I don’t know how many axes A have. What is the correct syntax for this purpose?

---

## [Is there a clean one-liner to subset a vector of vectors?](https://discourse.julialang.org/t/is-there-a-clean-one-liner-to-subset-a-vector-of-vectors/107249)

<div class="topic-metadata">

**Author:** [@Tetrakai](https://discourse.julialang.org/u/Tetrakai)\
**Replies:** 6\
**Last updated:** [December 7, 2023, 8:34pm UTC](https://discourse.julialang.org/t/is-there-a-clean-one-liner-to-subset-a-vector-of-vectors/107249 "2023-12-07T20:34:30Z")

</div>

I have something like this: julia\> A = \[\[1,\[2,3\]\], \[4,\[5,6\]\], \[7,\[8,9\]\]\] 3-element Vector{Vector{Any}}: \[1, \[2, 3\]\] \[4, \[5, 6\]\] \[7, \[8, 9\]\] julia\> B = \[A\[i\]\[2\]\[1\] for i in 1:length(A)\] 3-element Vector{Int64}: 2 5…

---

## [Performance difference depending on order of comparison in loop](https://discourse.julialang.org/t/performance-difference-depending-on-order-of-comparison-in-loop/107040)

<div class="topic-metadata">

**Author:** [@wheeheee](https://discourse.julialang.org/u/wheeheee)\
**Replies:** 3\
**Last updated:** [December 2, 2023, 1:05pm UTC](https://discourse.julialang.org/t/performance-difference-depending-on-order-of-comparison-in-loop/107040 "2023-12-02T13:05:14Z")

</div>

Unexpectedly, the following function has very different performance depending on the argument order of two matrices, which should be equivalent function f2(x, y; init=0) total = init for i in eachindex(x, y) …

---

## [Creating a tensor (array) in the tensor product of super vector spaces](https://discourse.julialang.org/t/creating-a-tensor-array-in-the-tensor-product-of-super-vector-spaces/106657)

<div class="topic-metadata">

**Author:** [@Yue-Zhengyuan](https://discourse.julialang.org/u/Yue-Zhengyuan)\
**Replies:** 8\
**Last updated:** [November 26, 2023, 1:15am UTC](https://discourse.julialang.org/t/creating-a-tensor-array-in-the-tensor-product-of-super-vector-spaces/106657 "2023-11-26T01:15:54Z")

</div>

I want to create a custom array of arrays (each array is called a “block”) indexed by a list of 0 and 1’s. For example, suppose the array has 4 dimensions; then. The arrays are indexed by (0,0,0,0), (0,0,0,1), (0,0,1,0…

---

## [Strange logical indexing behavior with 3-dimensional Array and BitMatrix](https://discourse.julialang.org/t/strange-logical-indexing-behavior-with-3-dimensional-array-and-bitmatrix/106221)

<div class="topic-metadata">

**Author:** [@bgroenks](https://discourse.julialang.org/u/bgroenks)\
**Replies:** 3\
**Last updated:** [November 14, 2023, 4:31pm UTC](https://discourse.julialang.org/t/strange-logical-indexing-behavior-with-3-dimensional-array-and-bitmatrix/106221 "2023-11-14T16:31:05Z")

</div>

Hi, A colleague of mine noticed something strange in the way that getindex and setindex! handle logical indexing with BitMatrix. Consider the following example: import Random X = ones(10,3,3) # Array{Float64,3} mask =…

---

## [Indexing an array with an array of indices](https://discourse.julialang.org/t/indexing-an-array-with-an-array-of-indices/104533)

<div class="topic-metadata">

**Author:** [@wosined](https://discourse.julialang.org/u/wosined)\
**Replies:** 5\
**Last updated:** [October 3, 2023, 2:21pm UTC](https://discourse.julialang.org/t/indexing-an-array-with-an-array-of-indices/104533 "2023-10-03T14:21:38Z")

</div>

I have a multidimensional array A = \[ 0 for x=1:5,y=1:5,z=1:5\] I also have an array of indices I = \[1,2,3\] I wish to get the element of A at the indices determined by I. For example I want to retrieve A\[1,2,3\] …

---

## [Combining \`eachindex\` and \`axes\`?](https://discourse.julialang.org/t/combining-eachindex-and-axes/104442)

<div class="topic-metadata">

**Author:** [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Replies:** 2\
**Last updated:** [October 2, 2023, 1:28pm UTC](https://discourse.julialang.org/t/combining-eachindex-and-axes/104442 "2023-10-02T13:28:43Z")

</div>

One of the things I like about eachindex is that you can give it several arrays and it throws a DimensionMismatch if they have different sizes. I wonder if it would make sense to enable the same with axes(A, d), possibl…

---

## [In-place assignment, without allocation](https://discourse.julialang.org/t/in-place-assignment-without-allocation/103811)

<div class="topic-metadata">

**Author:** [@user664303](https://discourse.julialang.org/u/user664303)\
**Replies:** 8\
**Last updated:** [September 13, 2023, 1:17pm UTC](https://discourse.julialang.org/t/in-place-assignment-without-allocation/103811 "2023-09-13T13:17:45Z")

</div>

I’m trying to do y = x\[ind\] in-place, where y, x, ind are all vectors. By in-place, I mean no memory is allocated. I’m able to achieve this using a hand-written for loop (assign2! below). I suspect there is a way to achi…

---

## [Convert matrix of 3D arrays to 3D array](https://discourse.julialang.org/t/convert-matrix-of-3d-arrays-to-3d-array/101888)

<div class="topic-metadata">

**Author:** [@mastrof](https://discourse.julialang.org/u/mastrof)\
**Replies:** 12\
**Last updated:** [July 23, 2023, 9:05am UTC](https://discourse.julialang.org/t/convert-matrix-of-3d-arrays-to-3d-array/101888 "2023-07-23T09:05:04Z")

</div>

I have N^2 3D arrays, all with size (nx, ny, nz). These arrays are arranged in a square matrix (N x N). I would like to expand the inner arrays concatenating them along the first two dimensions but not along the third, s…

---

## [Iterating over elements of upper triangular matrix, but cartesian indices are needed](https://discourse.julialang.org/t/iterating-over-elements-of-upper-triangular-matrix-but-cartesian-indices-are-needed/65498)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 17\
**Last updated:** [July 17, 2023, 1:13pm UTC](https://discourse.julialang.org/t/iterating-over-elements-of-upper-triangular-matrix-but-cartesian-indices-are-needed/65498 "2023-07-17T13:13:46Z")

</div>

Basically what I (think) I need is this function: https://stackoverflow.com/questions/27086195/linear-index-upper-triangular-matrix Of course I can just implement it, two lines of code. But that seems something that pr…

---

## [Get index corresponding to some number in list of outputs](https://discourse.julialang.org/t/get-index-corresponding-to-some-number-in-list-of-outputs/101068)

<div class="topic-metadata">

**Author:** [@raman\_kumar](https://discourse.julialang.org/u/raman_kumar)\
**Replies:** 24\
**Last updated:** [July 10, 2023, 3:43am UTC](https://discourse.julialang.org/t/get-index-corresponding-to-some-number-in-list-of-outputs/101068 "2023-07-10T03:43:39Z")

</div>

I want to get indices in lines corresponding to A=0 in output. :face\_with\_monocle: My goal is to get out the data between row index 14 and 23 of the lines variable output in terms of variable i. using HTTP , Gumbo , C…

---

## [Indexing on a pseudo-dimension](https://discourse.julialang.org/t/indexing-on-a-pseudo-dimension/101119)

<div class="topic-metadata">

**Author:** [@croberts](https://discourse.julialang.org/u/croberts)\
**Replies:** 10\
**Last updated:** [July 4, 2023, 2:43pm UTC](https://discourse.julialang.org/t/indexing-on-a-pseudo-dimension/101119 "2023-07-04T14:43:21Z")

</div>

Suppose I have a K x M array, my\_arr, but I want to pretend that it is a K x M x N array, my\_pseudo\_arr , so that indexing it with my\_pseudo\_arr\[k, m, n\] equals my\_arr\[k, m\], my\_pseudo\_arr\[k, m, :\] equals repeat(\[my\_arr\[…

---

## [Check the sum of a certain array index](https://discourse.julialang.org/t/check-the-sum-of-a-certain-array-index/100552)

<div class="topic-metadata">

**Author:** [@divon](https://discourse.julialang.org/u/divon)\
**Replies:** 19\
**Last updated:** [June 20, 2023, 7:40am UTC](https://discourse.julialang.org/t/check-the-sum-of-a-certain-array-index/100552 "2023-06-20T07:40:34Z")

</div>

Hello everyone, I would like to check the sum of certain indexes in the array. For example, I have the array: a = \[0, 0, 0, 1, 0, 1, 0, 1\] b = \[1, 2, 3, 5\] I will check the sum of a\[1\], a\[2\], a\[3\], and a\[5\]. If the su…

---

## [Why does the following setindex call allocate?](https://discourse.julialang.org/t/why-does-the-following-setindex-call-allocate/100216)

<div class="topic-metadata">

**Author:** [@jishnub](https://discourse.julialang.org/u/jishnub)\
**Replies:** 6\
**Last updated:** [June 12, 2023, 10:15am UTC](https://discourse.julialang.org/t/why-does-the-following-setindex-call-allocate/100216 "2023-06-12T10:15:04Z")

</div>

julia\> function f!(v, A, r) v\[eachindex(r)\] = @view A\[r\] v end f! (generic function with 1 method) julia\> v = zeros(10); A = ones(4,10); julia\> @btime f!($v, $A, 4:3:13); 56.050 ns (2 all…

---

## [Illegal memory indexing for broadcast of a recursive function](https://discourse.julialang.org/t/illegal-memory-indexing-for-broadcast-of-a-recursive-function/99534)

<div class="topic-metadata">

**Author:** [@albertomercurio](https://discourse.julialang.org/u/albertomercurio)\
**Replies:** 6\
**Last updated:** [May 31, 2023, 7:20am UTC](https://discourse.julialang.org/t/illegal-memory-indexing-for-broadcast-of-a-recursive-function/99534 "2023-05-31T07:20:16Z")

</div>

Hello, I’m trying to implement the generalized Laguerre function acting element-wise to the elements of a CuArray. The basic code uses a recursive function to evaluate the laguerre polynomial using CUDA using LinearAl…

---

## [Vector{Vector} indices](https://discourse.julialang.org/t/vector-vector-indices/87418)

<div class="topic-metadata">

**Author:** [@unhandyandy](https://discourse.julialang.org/u/unhandyandy)\
**Replies:** 22\
**Last updated:** [September 19, 2022, 5:36am UTC](https://discourse.julialang.org/t/vector-vector-indices/87418 "2022-09-19T05:36:00Z")

</div>

This is a trivial issue, but it puzzles me, and makes me think I don’t understand Julia arrays. With julia\> test = \[\[1,2\],\[3,4\]\] 2-element Vector{Vector{Int64}}: \[1, 2\] \[3, 4\] then julia\> test\[1\] 2-element Vector{I…

---

## [Create a matrix with given dimension](https://discourse.julialang.org/t/create-a-matrix-with-given-dimension/98066)

<div class="topic-metadata">

**Author:** [@angeloaliano1](https://discourse.julialang.org/u/angeloaliano1)\
**Replies:** 2\
**Last updated:** [April 29, 2023, 12:59am UTC](https://discourse.julialang.org/t/create-a-matrix-with-given-dimension/98066 "2023-04-29T00:59:07Z")

</div>

Dear all, I need to creeate a null three-dimensional matrix d = d\[s,l,t\] where s = \[2,3,4,5\], l=\[12,13,14,15,16\] and t=1:12, e.g, I don’t need for example of positions \[1,1,1\], \[1,2,1\], etc, but only in the ranges of th…

---

## [Extra dimensions and CartesianIndices](https://discourse.julialang.org/t/extra-dimensions-and-cartesianindices/97665)

<div class="topic-metadata">

**Author:** [@danicaratelli](https://discourse.julialang.org/u/danicaratelli)\
**Replies:** 2\
**Last updated:** [April 19, 2023, 5:35pm UTC](https://discourse.julialang.org/t/extra-dimensions-and-cartesianindices/97665 "2023-04-19T17:35:17Z")

</div>

Hello, I was wondering whether anyone has had to deal with “extra dimensions” while using ChartesianIndices. In particular, I am tempted to implement the following but it doesn’t work. Thanks in advance! N = 2; M = 2;…

---

## [Tullio with pre-computed index broadcasting](https://discourse.julialang.org/t/tullio-with-pre-computed-index-broadcasting/97345)

<div class="topic-metadata">

**Author:** [@ovt](https://discourse.julialang.org/u/ovt)\
**Replies:** 2\
**Last updated:** [April 11, 2023, 1:58pm UTC](https://discourse.julialang.org/t/tullio-with-pre-computed-index-broadcasting/97345 "2023-04-11T13:58:12Z")

</div>

It’s my first time with Tullio, so my problem may look very basic. Here is a minimal example that provides the error "expected integers!" : using Tullio m,r = 5,5 rr = div(r\*(r-1),2) A = rand(m,rr) B = rand(m,r) C = si…

---

## [Using end variable in ranges passed to functions other than getindex?](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591)

<div class="topic-metadata">

**Author:** [@tlnagy](https://discourse.julialang.org/u/tlnagy)\
**Replies:** 23\
**Last updated:** [March 29, 2023, 1:55pm UTC](https://discourse.julialang.org/t/using-end-variable-in-ranges-passed-to-functions-other-than-getindex/7591 "2023-03-29T13:55:47Z")

</div>

I expected the following to work: julia\> a = \[1,2,3,4,5\] 5-element Array{Int64,1}: 1 2 3 4 5 julia\> deleteat!(a, end-1:end) ERROR: syntax: unexpected "end" julia\> a\[end-1:end\] 2-element Array{Int64,1}: 4 5 I e…

---

## [IndexStyle for pairs iterator?](https://discourse.julialang.org/t/indexstyle-for-pairs-iterator/96450)

<div class="topic-metadata">

**Author:** [@DNF](https://discourse.julialang.org/u/DNF)\
**Replies:** 0\
**Last updated:** [March 22, 2023, 3:06pm UTC](https://discourse.julialang.org/t/indexstyle-for-pairs-iterator/96450 "2023-03-22T15:06:40Z")

</div>

I was a bit surprised to see that the pairs iterator for Matrix returns CartesianIndices by default. The docstring of pairs includes a section on specifying index style, showing these three signatures: pairs(IndexLinear…

---

## [Multidimensional arrays as indices in setindex!: bug or feature?](https://discourse.julialang.org/t/multidimensional-arrays-as-indices-in-setindex-bug-or-feature/94558)

<div class="topic-metadata">

**Author:** [@Az9DBvyVLWBjs8g](https://discourse.julialang.org/u/Az9DBvyVLWBjs8g)\
**Replies:** 1\
**Last updated:** [February 13, 2023, 2:29pm UTC](https://discourse.julialang.org/t/multidimensional-arrays-as-indices-in-setindex-bug-or-feature/94558 "2023-02-13T14:29:56Z")

</div>

Hello everyone, I just found that one can use multidimensional arrays as indices within setindex!. They behave as 1d arrays, which is different from their behavior in getindex, thus the following assertion from the docs …

---

## [Find position of Array elements in another Array](https://discourse.julialang.org/t/find-position-of-array-elements-in-another-array/39977)

<div class="topic-metadata">

**Author:** [@sergevic](https://discourse.julialang.org/u/sergevic)\
**Replies:** 16\
**Last updated:** [February 1, 2023, 2:59pm UTC](https://discourse.julialang.org/t/find-position-of-array-elements-in-another-array/39977 "2023-02-01T14:59:16Z")

</div>

Suppose I have the Array a=\[0.5, 0.6, 0.5, 0.4, 0.5, 0.6\] and a reference Array b=\[0.4, 0.5, 0.6\]. I want to to find the position in b of each element of a. I want then to obtain the output \[2, 3, 2, 1, 2, 3\]. I tried …

---

## [Delete a specific row and Colum in matrix](https://discourse.julialang.org/t/delete-a-specific-row-and-colum-in-matrix/92754)

<div class="topic-metadata">

**Author:** [@ahmad88](https://discourse.julialang.org/u/ahmad88)\
**Replies:** 13\
**Last updated:** [January 11, 2023, 12:54pm UTC](https://discourse.julialang.org/t/delete-a-specific-row-and-colum-in-matrix/92754 "2023-01-11T12:54:21Z")

</div>

I have a matrix of size nn and I have a list containing specific nodes in the graph in each iteration I have to remove the specific row and corresponding column based on the value in the list, how do I can know the speci…

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

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