Questions tagged [array-indexing]

Use this tag for questions about how to construct and interpret indices for retrieval of or assignment to non-trivial subsets or reorderings of multidimensional arrays.

Arrays are usually indexed numerically along their different dimensions. However, some packages, like numpy and MATLAB, allow for more complex objects to be used to compute the numerical indices. Questions with this tag should refer to such non-trivial indices. Examples include boolean masks, lists of integers (which behave differently in different languages), and linear indices into a multidimensional array.

75 questions
0
votes
0 answers

I need to use the value stored into a10[1] and use that as an index into another array in Keil

Here is my instructions: Set a “Result” register value equal to the result of the behavior described here: index0 = a10[0]; index1 = a10[1]; Result = Result + a10[ index0 ] + a10[ index1 ] * a10[ index1 ]; Here is what I have so far MOV R11…
0
votes
0 answers

C# Array with specific LowerBound

This question for learning C#, and not a real problem. I was reading in C# that you can create an Array with custom LowerBound so it won't start from Zero. I thought this might be useful where I can store objects with numbers starting from n -> to…
Ghassan Karwchan
  • 3,355
  • 7
  • 37
  • 65
0
votes
4 answers

last index of array give wrong output in c

I created a program that search the specific number in array and give it position. here's the code. #include #include void main() { int arr[10], srch, i; clrscr(); printf("Enter elements of array.\n"); …
0
votes
1 answer

How to reassign/replace a value of an array by index if its in a global state

I have a global state that is an array [1,0, null,1,0....] I want to access the array by index let's say index 5 I want just to replace that value with 1 I have the array and I have the index but I don't know how to reassign and update the…
Edd
  • 3
  • 2
0
votes
1 answer

fill remaining indexes in array with null values

I need to adjust for blank days in my calendar app. There should be 35 blocks to make up the calendar, but I need to fill the array with 30 items inside of that. Is there a method that allows that? so far this just pushes the days, but you will…
lache
  • 608
  • 2
  • 12
  • 29
0
votes
0 answers

np.array([0, 0, 0]) [ [1, 2, 2] ] += [4, 5, 6] does not accumulate

All arrays in the following are NumPy arrays. I have an array of numbers, say a = [4, 5, 6]. I want to add them to an accumulation array, say s = [0, 0, 0] but I want to control which number goes to where. For instance, I want s[1] += a[0], s[2] +=…
Symbol 1
  • 123
  • 4
0
votes
1 answer

Indices in Numpy and MATLAB

I have a piece of code in Matlab that I want to convert into Python/numpy. I have a matrix ind which has the dimensions (32768, 24). I have another matrix X which has the dimensions (98304, 6). When I perform the operation result = X(ind) the shape…
0
votes
2 answers

Product of array in a new array except the current index value

Given an array of integers, create a new array such that each element at index i of the new array is the product of all the numbers in the original array except the one at i. For example, if our input was [1, 2, 3, 4, 5], the expected output would…
Nitesh Singh
  • 45
  • 1
  • 9
0
votes
3 answers

Indexing multidimensional array

Is it possible in Java to index an Array somehow like arr1[arr2] if arr1 is an int[][] and arr2 an int[2]. I would like a better way to achieve the same as arr1[arr2[0]][arr2[1]] which looks really awfull. And by better I mean easier to read and…
0
votes
2 answers

Incremental and Decremental of javascript array

I'm trying to create simple image modal using angular material. next() supposed to be view next image from the array and prev() view previous image. Problem next and prev function not working as expected. If click next() index only increase +1 then…
0
votes
0 answers

Can't access array value when my index is a variable

I have a problem accessing a value stored in my 2D array... When I write the index as a number, it works but when my index is a variable (which contains a number) it does not work... Here is my code: #include const char eQ1[]…
0
votes
1 answer

Assign values of vertical vector from matrix to variables in MATLAB r2019b

What I want to be able to do is to take the elements of a vertical vector from a matrix and assign them to variables. I have provided a simple example below to show what I want to happen. for k = 1 : 20 a(:,k) = [k k+2]; end [b, c] = a(:,…
0
votes
1 answer

Making a back button using previous state of the array index

I'm making a back button for a decision tree. The tree is made out of an array and its index. Right now, yes or no will take them to a different part of the array index as a response. I'm trying to find a way to capture the previous useState array…
0
votes
1 answer

Sub-array using $p$ commas

Say I have an array Y of size (n x m_1 x m_2 x m_3). If I want the first sub-array of size (m_1 x m_2 x m_3) I can choose it using commas as Y(1,,,) Similarly, if Y is of size (n x m_1 x m_2 x m_3 x m_4) and I want the first sub-array of size (m_1…
Carlos Llosa
  • 123
  • 6
0
votes
0 answers

Why does Kotlin in Android Studio freeze when trying to access non existent array element?

I've come across interesting behavior of Kotlin in Android Studio. When I try to log an element of an array dynamically where the index supplied is -1 and the array is empty, the program freezes in the emulator but never throws an error. Example…
Mr.Drew
  • 939
  • 2
  • 9
  • 30