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
11
votes
2 answers

Python TypeError : only integer scalar arrays can be converted to a scalar index

I have made for this question an easier example of two arrays: The labelArray is a 1D-array has labels at indices which corresponds to the same indices of the nD-array someValuesArray. I get all indices where label 2 occurs and want to retrieve the…
grajkowski
  • 349
  • 1
  • 3
  • 14
11
votes
2 answers

Print a matrix without row and column indices

If I print a matrix, it is shown with row and column indices in the console. E.g. > print(diag(3)) [,1] [,2] [,3] [1,] 1 0 0 [2,] 0 1 0 [3,] 0 0 1 How can I suppress the column and row indices? I.e. something like…
Jonas Lindeløv
  • 5,442
  • 6
  • 31
  • 54
11
votes
1 answer

Get the first column of a matrix represented by a vector of vectors

Suppose I'm representing a matrix foo of values using std::vector: int rows = 5; int cols = 10; auto foo = vector>(rows, vector(cols)); Is there a cleverly simple way for me to get a vector of size rows that contains…
Alan Turing
  • 12,223
  • 16
  • 74
  • 116
10
votes
4 answers

Does anyone know of an R code to calculate Palmer Drought Severity Index (PDSI)?

Palmer drought severity index is one of the most popular moisture/drought indices around. There is a package in R called a SPEI that allows calculation of two other popular drought indices (Standardised precipitation index and Standardised…
user2760
  • 2,273
  • 7
  • 25
  • 34
10
votes
3 answers

Python numpy array sum over certain indices

How to perform a sum just for a list of indices over numpy array, e.g., if I have an array a = [1,2,3,4] and a list of indices to sum, indices = [0, 2] and I want a fast operation to give me the answer 4 because the value for summing value at index…
Marcus_Ma
  • 155
  • 1
  • 1
  • 6
9
votes
2 answers

How to select indices according to another tensor in pytorch

The task seems to be simple, but I cannot figure out how to do it. So what I have are two tensors: an indices tensor indices with shape (2, 5, 2), where the last dimensions corresponds to indices in x and y dimension a "value tensor" value with…
spadel
  • 998
  • 2
  • 16
  • 40
9
votes
2 answers

Julia: Find the indices of all maxima

In Julia you can use findmax or indmax to find the index of the biggest entry in a matrix. But if you have multiple entries with this maximum value, you get the index of the first one. How can I get the indices of all max value entries in a matrix?
Code Pope
  • 5,075
  • 8
  • 26
  • 68
9
votes
1 answer

perl6 Best ways to sort array of arrays?

I need to sort an array of arrays; the .sort method seems to work by default. But what is a good way to sort by different indices of the inner arrays? array to be sorted is outter larger array: (birthday in 'mmddyy' format) my @allRecords = […
lisprogtor
  • 5,677
  • 11
  • 17
9
votes
1 answer

Go loop indices for range on slice

I have a fairly simple question, but can't find answer anywhere. I'm iterating over a range of slices, like this: for index, arg := range os.Args[1:] { s += fmt.Sprintf("%d: %s", index, arg) } As I understand range iterates over a slice, and…
Damaged Organic
  • 8,175
  • 6
  • 58
  • 84
9
votes
1 answer

Multiply two pandas series with mismatched indices

Created two series: s1 and s2 from df. Each have same length but differing indices. s1.multiply(s2) unions the mismatched indices instead of multiplying against them. I just want to multiply entrywise s1 against s2 ignoring the mismatched indices. I…
lebca
  • 185
  • 2
  • 5
9
votes
3 answers

Randomly extract x items from a list using python

Starting with two lists such as: lstOne = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] lstTwo = [ '1', '2', '3', '4', '5', '6', '7', '8', '9', '10'] I want to have the user input how many items they want to extract, as a percentage of the…
PaulBarr
  • 919
  • 6
  • 19
  • 33
9
votes
6 answers

Find Positions of a Character in a String

How can I find a character in a String and print the position of character all over the string? For example, I want to find positions of 'o' in this string : "you are awesome honey" and get the answer = 1 12 17. I wrote this, but it doesn't work :…
Rastin Radvar
  • 143
  • 1
  • 1
  • 8
9
votes
2 answers

list match in python: get indices of a sub-list in a larger list

For two lists, a = [1, 2, 9, 3, 8, ...] (no duplicate values in a, but a is very big) b = [1, 9, 1,...] (set(b) is a subset of set(a), 1<
user1342516
  • 447
  • 2
  • 5
  • 10
8
votes
3 answers

C# rows of multi-dimensional arrays

In the C# programming language, how do I pass a row of a multi-dimensional array? For example, suppose I have the following: int[,] foo; foo = new int[6,4]; int[] least; least = new int[6]; for(int i = 0; i < 6; i++) { least[i] = FindLeast(ref…
CodeKingPlusPlus
  • 15,383
  • 51
  • 135
  • 216
8
votes
4 answers

Sum elements with conditions on indices

I have 3 vectors: x <- c(3, 5, 2) y <- c(3, 2, 1, 1, 2, 3, 4, 5, 4, 5) z <- c(2, 4, 8, 1, 5) x is the number of elements in each group. y gives indices to extract elements from z. The first three indices belong to group 1 (corresponding to first…
Sarah
  • 81
  • 3
1 2
3
58 59