Questions tagged [indices]

Use this tag for questions about specifying or selecting the correct information from a structure using indices.

For any set of records, indices are identifiers of which specify information of the address of each record.

Check the Wikipedia page for arrays to know more.

882 questions
5
votes
3 answers

Sum all numbers in a given range of a given list Python

How can I write a function to get the sum of the items in the given list between the indices a and b. For example give aList=[6,3,4,2,5] and a=1, b=3, the function should return 9. Here is my code: def sumRange(L,a,b): sum= [] L =…
nightowl_nicky
  • 341
  • 1
  • 5
  • 14
5
votes
1 answer

reset_index() to original column indices after pandas groupby()?

I generate a grouped dataframe df = df.groupby(['X','Y']).max() which I then want to write (to csv, without indexes). So I need to convert 'X' and 'Y' back to regular columns; I tried using reset_index(), but the order of columns was wrong. How to…
bkd
  • 170
  • 12
5
votes
2 answers

Find indices of common values in two arrays

I'm using Python 2.7. I have two arrays, A and B. To find the indices of the elements in A that are present in B, I can do A_inds = np.in1d(A,B) I also want to get the indices of the elements in B that are present in A, i.e. the indices in B of…
berkelem
  • 2,005
  • 3
  • 18
  • 36
5
votes
2 answers

Indices trick used for several components

Consider this fully working code: #include template struct Make; template class P, T... Indices> struct Make> { using type = P<(Indices+1)...,…
prestokeys
  • 4,817
  • 3
  • 20
  • 43
5
votes
2 answers

Matlab: Find row indice of first occurrence for each column of matrix (without using loops)

For each column of a matrix A consisting of '0' and '1', I would like to find the column indices of the first occurrence of '1' if exists. For example, if A is defined as: A=[0 0 0 0; 0 0 0 1; 0 0 0 0; 0 0 0 1; 1 0 0 0; 0 1 0 1; 1 1 0…
MikeSchneeberger
  • 463
  • 5
  • 10
5
votes
1 answer

How to handle COLLADA indices?

I wrote a simple reader for the COLLADA file format, and it seems to work OK. Now, I have a Blender-exported cube mesh which is edge-splitted and triangulated, so it should have 12 triangles (2 per face), 24 vertices (4 per face) and 36 indices (6…
manabreak
  • 5,415
  • 7
  • 39
  • 96
4
votes
1 answer

Indices of k-minimum values along an axis of a numpy array

Is there a way to return the indices of k-minimum values along an axis of a numpy array without using loops?
Academia
  • 3,984
  • 6
  • 32
  • 49
4
votes
4 answers

Retrieving largest indices of the bounded element in a multidimensional array in Scala

I have an multidimensional Array: val M = Array.ofDim[Int](V, N) Goal is to find largest V dimension index for which there exists a bounded element 0 < w0 <= W and return both indices and element value. Currently I have this code snippet which…
Paulius
  • 363
  • 1
  • 7
4
votes
3 answers

C# improper result of index range expression

I'm slightly confused with index range operator: I expected that the expression myString[..0] should be equvalent to myString[0..0], then myString.Substring(0, 1) or myString[0].ToString(), and in case of code below: string myString = " abc"; string…
VillageTech
  • 1,968
  • 8
  • 18
4
votes
5 answers

How can I find matching elements and indices from two arrays?

For example, a = [1, 1, 2, 4, 4, 4, 5, 6, 7, 100] b = [1, 2, 2, 2, 2, 4, 5, 7, 8, 100] I can find the matching elements using: np.intersect1d(a,b) Output: array([ 1, 2, 4, 5, 7, 100]) Then, how can I get the indices of matched elements…
이원석
  • 87
  • 2
  • 5
4
votes
4 answers

Indices of duplicate lists in a nested list

I am trying to solve a problem that is a part of my genome alignment project. The problem goes as follows: if given a nested list y = [[1,2,3],[1,2,3],[3,4,5],[6,5,4],[4,2,5],[4,2,5],[1,2,8],[1,2,3]] extract indices of unique lists into a nested…
sindhuja
  • 167
  • 1
  • 12
4
votes
2 answers

Using HashMap with Integers ( indices ) as keys vs using an ArrayList

So I'm currently making my own version of Pokemon replicated in Java. I've only gotten familiar with more advanced data structures very recently and I'm still not sure when one should be more appropriate than the other. Basically, I want to store a…
PreciseMotion
  • 330
  • 1
  • 14
4
votes
1 answer

Google Earth Engine: how to map a function over a collection of all Landsat sensors to create NDVI timeseries

I am trying to combine all the Landsat sensors (L4-l8) from 1980s to present in Google Earth Engine, and calculate the time-series of the NDVI index (after having removed the clouds) I tried to find a work around to solve the issue that L8 uses…
user21074
  • 63
  • 1
  • 5
4
votes
1 answer

Rearrange list in-place by modifying the original list, put even-index values at front

I am relatively new to python and I am still trying to learn the basics of the language. I stumbled upon a question which asks you to rearrange the list by modifying the original. What you are supposed to do is move all the even index values to the…
Nauman Shahid
  • 377
  • 1
  • 10
4
votes
1 answer

numpy: Is there a way to create an array from a sequence of mappings w/o external loop?

To me, this sounds like a common use-case, but I couldn't find the proper function/thread for it, yet. I have two numpy arrays, one is a sequence of triplets and the other the associated sequence of indices. I want to create a 1-dim array of equal…
Michael S.
  • 150
  • 1
  • 9