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
1 answer

How to modify index being accessed in an array

EDIT: in my case, it was easier to just check the bool value and if it was true, simply remove the first 0x200 (decimal 512) bytes from the array so any future access to the array wouldn't need to worry about it, basically meaning that if the bool…
Vawlpe
  • 97
  • 1
  • 8
0
votes
1 answer

R - forcing a set of indexed rows to always be a matrix (or array)

I have a matrix that I need to filter by a condition. yj = y[which(g[,j] == 1),] A problem arises when "which(g[,j] == 1)" is a 1 (or none) component vector. The output, the aforementioned "yj", is then suddenly a vector. I need to be able to…
Faydey
  • 725
  • 1
  • 5
  • 12
0
votes
2 answers

Python `arr[0]:[0]` explanation

This code snippet is one of posts in a LeetCode problem by fukuzawa_yumi def splitArray(self, nums): d,n={nums[0]:[0]},len(nums) for i in range(1,n): nums[i]+=nums[i-1] if nums[i] not in d: d[nums[i]]=[i] else:…
0
votes
1 answer

How index starts with 1 in revel Framework

rank abc {{ range $index,$abc := .abc }} {{$index}} // 0 {{$abc}} {{end}} how to {{$index}} starts with 1 {{add $index 1}} - unction "add" not…
Revllllł1
  • 13
  • 2
0
votes
1 answer

A way for picking specific indices from an object where slicing isn't helpful

I'm looking for a way to access an object multiple times in an easy way. Ex. 1) ls = [i for i in range(100)]; print(ls[0], ls[32], ls[95]) Ex. 2) js = {'key0': 'val0', ...}; print (js['keyN'], js['keyM']) What I'm looking for is a way to only…
CIsForCookies
  • 12,097
  • 11
  • 59
  • 124
0
votes
1 answer

How can I perform an action by setting up an if statement on the indexes between two 1-D arrays?

string[] words1 = new string[] { "How are you?", "Where are you?" }; string[] words2 = new string[] { "I'm fine.", "I'm outside." }; // how do I perform an action by showing the indexes are same if…
Tanjim
  • 3
  • 1
  • 6
0
votes
0 answers

twig - looping same array index result

I am returning array results trough my twig file. I have accessed them but when I render them with "for" I got just first result rendered three times. (number of rows in my db.) On dump () this is what I get: I don't know how to acces them all…
develops
  • 279
  • 1
  • 5
  • 14
-1
votes
1 answer

JQuery for each function get array index

I have an array as follows: result = []; result.push({label: 'test label 1', value: 'test value 1'}); result.push({label: 'test label 2', value: 'test value 2'}); $.each(result, function( key, value ) { console.log(key); …
adam78
  • 9,668
  • 24
  • 96
  • 207
-1
votes
1 answer

iOS/Swift: why contains doesn't work to detect a substring in the .firstIndex function?

I am using the function .firstIndex to locate a specific substring in an array of arrays. But when I put the entire string, it works, but if I put only a substring of that string, this doesn't work. let index = programArray.firstIndex(where:…
ΩlostA
  • 2,501
  • 5
  • 27
  • 63
-1
votes
1 answer

Is it possible to overload [] operator to do different thing in C++

I want to overload "[]" witch is used to access array But I also want to separate read/write to do different thing For example : class myclass{ private: int val; public: myclass(){val=0;} myclass(int _in){val=_in;} .... //for…
-1
votes
3 answers

Easier way to represent indicies in a 2D array

I'm new to programming and I've created a simple tic-tac-toe game. It took an input of the row and column of a 2d array. However, I want to make it simpler and use a value of 1-9 instead to represent each square on the board. The way I've gone about…
lukeyp
  • 13
  • 4
-1
votes
1 answer

Is there a way to convert a multi_index into a int string / list / array?

I want to change a value of given array in numpy to a multiplication of other elements of the array. Therefore I want to extract the multi_index and manipulate it so that I can identify the position and use it. (e.g. nditer through all elements and…
-1
votes
2 answers

What is the best way to keep dimensionality when subarraying numpy arrays?

Suppose I had a standard numpy array such as a = np.arange(6).reshape((2,3)) When I subarray the array, by performing such task as a[1, :] I will lose dimensionality and it will turn into 1D and print, array([3, 4, 5]) Of course the list being 2D…
J.Doe
  • 3
  • 2
-2
votes
3 answers

How to make a +5 (or any +number) jump in array values inside a for loop?

So i have a column of data which consists of numbers where i have to find 5 instances of the same number. So ,for example, 8,8,8,8,8,8,8,8,8,9,9,9,5,6,4,7,,6,2,3, etc. In this 8 has occurred 9 times. So i want to increment the count only once…
-2
votes
2 answers

JS Function that checks a dynamic number of index positions and returns array element if it satisfies the condition

I've been looking for a way to return elements in an array based on a dynamic number. This dynamic number will be the number of required index positions for each array element, if each element can satisfy the required number of index positions (its…
codenoob9000
  • 47
  • 1
  • 7
1 2 3 4
5