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

C# 8 way to get last n characters from a string

Recently VS hinted me to use the: var str = "foo"; var str2 = str[^2..]; Instead of the: var str = "foo"; var str2 = str.Substring(str.Length - 2); So, my question is are there any differences between the str[^2..] and the str.Substring(str.Length…
manymanymore
  • 2,251
  • 3
  • 26
  • 48
8
votes
4 answers

How to resolve "IndexError: too many indices for array"

My code below is giving me the following error "IndexError: too many indices for array". I am quite new to machine learning so I do not have any idea about how to solve this. Any kind of help would be appreciated. train =…
Sujoy De
  • 229
  • 2
  • 3
  • 11
8
votes
2 answers

Python negative subscripting

I'm currently reading Robert Sebesta's Concepts of Programming Languages, 10th edition (2012). In the chapter about data types, it reads "Ruby and Lua support negative subscripts, but Python does not". I thought negatives subscripts could be done in…
Felipe Cortez
  • 257
  • 3
  • 16
8
votes
5 answers

matlab: dividing vector into overlapping chunks of fixed size

I've a vector that I would like to split into overlapping subvectors of size cs in shifts of sh. Imagine the input vector is: v=[1 2 3 4 5 6 7 8 9 10 11 12 13]; % A=[1:13] given a chunksize of 4 (cs=4) and shift of 2 (sh=2), the result should look…
Tin
  • 1,006
  • 1
  • 15
  • 27
8
votes
2 answers

Get indices of K smallest or largest elements in each row of a matrix in R

How to get indices of K smallest or largest elements in eaach row of a matrix in R? E.g. I have matrix: 2 3 1 65 2 46 7 9 3 2 9 45 3 5 7 24 65 87 3 6 34 76 54 33 6 I'd like to get Indices matrix of say 2 smallest elements…
N D Thokare
  • 1,703
  • 6
  • 35
  • 57
7
votes
3 answers

How to invert numpy.where (np.where) function

I frequently use the numpy.where function to gather a tuple of indices of a matrix having some property. For example import numpy as np X = np.random.rand(3,3) >>> X array([[ 0.51035326, 0.41536004, 0.37821622], [ 0.32285063, 0.29847402, …
Setjmp
  • 27,279
  • 27
  • 74
  • 92
7
votes
6 answers

How to find indices of non zero elements in large sparse matrix?

i have two sq matrix (a, b) of size in order of 100000 X 100000. I have to take difference of these two matrix (c = a-b). Resultant matrix 'c' is a sparse matrix. I want to find the indices of all non-zero elements. I have to do this operation many…
Netro
  • 7,119
  • 6
  • 40
  • 58
7
votes
1 answer

SwiftUI ForEach with .indices() does not update after onDelete

my problem is: I have simple array with some Items. I want to display a List with these items using a ForEach with .indices(). (This is because my actual problem handles with Toggle in a List and for the isOn binding I need the index to address a…
user11960918
7
votes
3 answers

Find the minimum and maximum indices of a list given a condition

I have a list, let's say: list_A = [0,0,0,1.0,2.0,3.0,2.0,1.0,0,0,0] I would like to find the minimum and maximum indices of this list where list_A > 0, i.e. in the above example, it would be 3 and 7. For other lists, which increase…
Srivatsan
  • 9,225
  • 13
  • 58
  • 83
7
votes
1 answer

Python: Finding corresponding indices for an intersection of two lists

This is somewhat related to a question I asked not too long ago today. I am taking the intersection of two lists as follows: inter = set(NNSRCfile['datetimenew']).intersection(catdate) The two components that I am taking the intersection of…
user1620716
  • 1,463
  • 6
  • 17
  • 26
6
votes
2 answers

OpenGL ES - glDrawElements - Trouble Understanding Indices

I wonder if anyone can help me understand how indices work with glDrawElements. In the below example (taken from http://www.everita.com/lightwave-collada-and-opengles-on-the-iphone) the author mentions that you can only have one set of indices, in…
GuybrushThreepwood
  • 5,598
  • 9
  • 55
  • 113
6
votes
4 answers

Location of highest values in a matrix

Supose we have a matrix like this one: # Set seed set.seed(12345) # Generate data.frame df <- matrix(sample(1:100,100), nrow = 10) I would like to get the row and column where the first n highest values are placed. I know that using which(df…
R18
  • 1,476
  • 1
  • 8
  • 17
6
votes
4 answers

Adding values to a matrix using index vectors that include row and column names

Suppose I have a really big matrix of sparse data, but i'm only interested in looking at a sample of it making it even more sparse. Suppose I also have a dataframe of triples including columns for row/column/value of the data (imported from a csv…
dscheffy
  • 89
  • 1
  • 6
6
votes
1 answer

Filtering a @Binding array var in a ForEach in SwiftUI returns values based on unfiltered array

I'm a Windows C# developer, new to iOS/SwiftUI development and I think I've worked myself into a hole here. I have a view with a @Binding variable: struct DetailView: View { @Binding var project: Project The project is an object which contains…
sid
  • 148
  • 7
6
votes
1 answer

SQL Server two columns in index but query on only one

In legacy code I found an index as follows: CREATE CLUSTERED INDEX ix_MyTable_foo ON MyTable ( id ASC, name ASC ) If I understand correctly, this index would be useful for querying on column id alone, or id and name. Do I have that…
Developer Webs
  • 983
  • 9
  • 29