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

2D array random index Lotto game

I'm trying to do a Lotto game where I have to generate a random card and in the first column numbers go from 1-9, second 10-19 all the way to 90. Another rule of the card is that it can only have 5 numbers at random positions in each line and that's…
henryke9
  • 23
  • 3
2
votes
1 answer

Bigquery: Find the index at which a specified element is first found within an array

I'm working with Bigquery and I have a dataset with arrays where I'd like to extract the index at which a specified element is first found. I do not find a function in Bigquery to achieve what I want. Dataprep has arrayindexof function which does…
2
votes
2 answers

VHDL 2008: Index in external names containing generated instances

For a testbench, I'm trying to use external names to read signals within a DUT. It is not desired to export these signals outside of the DUT, so I concluded that using external names was the best option here. Unfortunately, there are some for…
2
votes
1 answer

Initializing arrays in VHDL: How exactly does it work?

Consider the following VHDL code: constant c : std_logic_vector(7 downto 0) := (7 downto 6 => '1', others => '0'); Here, the indices 7 and 6 are important: they indicate which elements should be 1, and from that, the compiler can derive which ones…
PieterNuyts
  • 496
  • 5
  • 20
2
votes
1 answer

K-means clustering error: only 0's may be mixed with negative subscripts

I am trying to do kmeans clustering on IRIS data in R. I want to use KKZ option for the seed selection (starting points of clusters). If i dont standardize the data i have no issues with the KKZ command: library(inaparc) res<- kkz(x=iris[,1:4], k=3)…
2
votes
3 answers

What does "20"[1] do?

In a test exam, we were told to find the value of some expressions. All but 1 were clear, which was "20"[1]. I thought it was the 1st index of the number, so 0, but testing with a computer it prints 48. What exactly does that 'function' do?
Drax
  • 141
  • 8
2
votes
1 answer

Couchbase 4.5 - Index is not covered when array is used in where clause

I have a Couchbase(4.5) bucket my-data. A minimal overview of the bucket is as follows. Document structure { _class: “com.dom.Activity”, depId: 984, dayIds: [17896, 17897, 17898], startTime: 10, endTime: 20 } Index I also have…
AJA
  • 456
  • 3
  • 12
2
votes
2 answers

Select different slices from each numpy row

I have a 3d tensor and I want to select different slices from the dim=2. something like a[[0, 1], :, [slice(2, 4), slice(1, 3)]]. a=np.arange(2*3*5).reshape(2, 3, 5) array([[[ 0, 1, 2, 3, 4], [ 5, 6, 7, 8, 9], [10, 11, 12,…
Separius
  • 1,226
  • 9
  • 24
1
vote
1 answer

Accessing the first index of an anonymous function

If I have an anonymous function in MATLAB, say f = @(t) [t, t+5]; and I wanted to create a new anonymous function g that accesses the first index of f, so that, in this example, g = @(t) t; how can I do so? I have tried doing something along the…
ShonenMind
  • 31
  • 2
1
vote
1 answer

Python Array variable assignment

I am newbie to python so having difficulty understand this code behavior for scenarios listed below. I can understand the first 3 where the output is a=[1], b=[0] but in the last case why is the value of b getting changed to [1] ? a = [0] b = a[:] a…
OhMoh24
  • 41
  • 6
1
vote
1 answer

My names are not being erased from the list. Assembly language x86

scrienume label let's me read from the keyboard 5 char names.The lista label displays each on one line along with their index(eg:if i write "daria" and "adria", the output is "1.daria", and on the next line is "2.maria"). The 3rd label should give…
Mihai
  • 31
  • 5
1
vote
1 answer

I want to filter the columns with condition '>0' and den find minimum value along filtered columns and sort them and get index of column using numpy

I am looking for this solution using Numpy, So anyone wish to do this operation/steps with minimal code it would help me a lot. Step 1. This is the given array arr_a= [[0, 1.2, -0.3, 8, 3, -4], [1.3, -0.9, 3.2, -7.2, -4.2, 5.1], [-2.1, 3.2, -3,…
1
vote
2 answers

NumPy 3D Array: Get items from a list of 2D co-ordinates

I have a numpy array that looks like follows. img = [ [ [135. 100. 72.], [124. 102. 63.], [161. 67. 59.], [102. 92. 165.], [127. 215. 155.] ], [ [254. 255. 255.], [216. 195. 238.], [109. 200. 141.], […
Romeo Sierra
  • 1,666
  • 1
  • 17
  • 35
1
vote
1 answer

The difference between double brackets vs single square brackets in python

I am trying to Sort the array by the second row. For n1, I use two square brackets [][] whereas for n2 I use a single square bracket [,]. I am trying to understand why do I get different results? Thank you in advance. import numpy sampleArray =…
Rahul v
  • 13
  • 2
1
vote
1 answer

Get Matrix 2D from Matrix 3D with a given choice of the third dimension corresponding to the first dimension

I have: A matrix 3D: A = (m, n, k). An array of choices for the third dimension corresponding to each index of the first dimension. idn = (m, 1) (wherein the value of any idn is a random integer in [1,k]. I need to capture the 2D matrix B (m,n)…
Romalpa Akzo
  • 599
  • 1
  • 4
  • 12