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
21
votes
7 answers

indices of the k largest elements in an unsorted length n array

I need to find the indices of the k largest elements of an unsorted, length n, array/vector in C++, with k < n. I have seen how to use nth_element() to find the k-th statistic, but I'm not sure if using this is the right choice for my problem as it…
Luke Peterson
  • 931
  • 1
  • 9
  • 25
20
votes
5 answers

Is a JavaScript array index a string or an integer?

I had a generic question about JavaScript arrays. Are array indices in JavaScript internally handled as strings? I read somewhere that because arrays are objects in JavaScript, the index is actually a string. I am a bit confused about this, and…
user3033194
  • 1,775
  • 7
  • 42
  • 63
20
votes
6 answers

How to number/label data-table by group-number from group_by?

I have a tbl_df where I want to group_by(u, v) for each distinct integer combination observed with (u, v). EDIT: this was subsequently resolved by adding the (now-deprecated) group_indices() back in dplyr 0.4.0 a) I then want to assign each…
smci
  • 32,567
  • 20
  • 113
  • 146
20
votes
6 answers

NumPy k-th diagonal indices

I'd like to do arithmetics with k-th diagonal of a numpy.array. I need those indices. For example, something like: >>> a = numpy.eye(2) >>> a[numpy.diag_indices(a, k=-1)] = 5 >>> a array([[ 1., 0.], [ 5., 1.]]) Unfortunately, diag_indices…
K3---rnc
  • 6,717
  • 3
  • 31
  • 46
20
votes
4 answers

compare two lists in python and return indices of matched values

For two lists a and b, how can I get the indices of values that appear in both? For example, a = [1, 2, 3, 4, 5] b = [9, 7, 6, 5, 1, 0] return_indices_of_a(a, b) would return [0,4], with (a[0],a[4]) = (1,5).
user1342516
  • 447
  • 2
  • 5
  • 10
18
votes
2 answers

numpy function to set elements of array to a value given a list of indices

I'm looking for a numpy function that will do the equivalent of: indices = set([1, 4, 5, 6, 7]) zero = numpy.zeros(10) for i in indices: zero[i] = 42
involucelate
  • 273
  • 2
  • 3
  • 7
17
votes
4 answers

Octave: find the minimum value in a row, and also it's index

How would one find the minimum value in each row, and also the index of the minimum value? octave:1> a = [1 2 3; 9 8 7; 5 4 6] a = 1 2 3 9 8 7 5 4 6
AG1
  • 6,648
  • 8
  • 40
  • 57
17
votes
1 answer

Is there an easy way to group columns in a Pandas DataFrame?

I am trying to use Pandas to represent motion-capture data, which has T measurements of the (x, y, z) locations of each of N markers. For example, with T=3 and N=4, the raw CSV data looks…
lmjohns3
  • 7,422
  • 5
  • 36
  • 56
16
votes
1 answer

Can someone please explain the "indices trick"?

I noticed the "indices trick" being mentioned in the context of pretty-printing tuples. It sounded interesting, so I followed the link. Well, that did not go well. I understood the question, but could really not follow what was going on. Why do we…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
15
votes
1 answer

SQLITE and autoindexing

I recently began exploring indexing in sqlite. I'm able to successfully create an index with my desired columns. After doing this I took a look at the database to see that the index was created successfully only to find that sqlite had already auto…
Warblr
  • 1,188
  • 1
  • 13
  • 27
13
votes
3 answers

Kibana - Get a list of all indices

I have ElasticSearch installed on a server and Kibana 3.0 installed on another machine. Is there any way to get a list of all the indices on the ElasticSearch server to show up on Kibana? Just like how ElasticSearch-Head displays it. Maybe in a new…
user3775873
  • 131
  • 1
  • 1
  • 3
13
votes
2 answers

SQLite3 how do I use indices?

I’m working on SQLite3 indices. Here’s a table COMAPNY: CREATE TABLE COMPANY( ID INT PRIMARY KEY NOT NULL, NAME TEXT NOT NULL, AGE INT NOT NULL, ADDRESS CHAR(50), SALARY REAL ); INSERT INTO COMPANY…
YOUNG
  • 515
  • 3
  • 13
12
votes
1 answer

mongoDB vs. elasticsearch query/aggregation performance comparison

This question is about choosing the type of database to run queries on for an application. Keeping other factors aside for the moment, and given that the choice is between mongodb and elastic, the key criterion is that the query should be resolved…
12
votes
5 answers

Cumulative summation of a numpy array by index

Assume you have an array of values that will need to be summed together d = [1,1,1,1,1] and a second array specifying which elements need to be summed together i = [0,0,1,2,2] The result will be stored in a new array of size max(i)+1. So for…
D R
  • 21,936
  • 38
  • 112
  • 149
12
votes
1 answer

Unexpected result when trying to compose a curried lambda with another lambda

I am toying with C++11 lambdas and was trying to mimick some function from the functional module of the D programming language. I was actually trying to implement curry and compose. Here is the main that I am trying to get working: int main() { …
Morwenn
  • 21,684
  • 12
  • 93
  • 152
1
2
3
58 59