Questions tagged [multidimensional-array]

Multidimensional-arrays can be described as multi-dimensional tables. Each index used in order to find a given element is called a dimension.

An array is typically a data structure meant to store a collection of elements to which is associated a given index. These elements are often in contiguous memory locations although this is not a requirement.

Multidimensional-arrays can be described as multi-dimensional tables. Each index used in order to find a given element is called a dimension.

Depending on the programming language, such a data structure can be achieved through a specific multi-dimension array data structure or in the shape of an "array of arrays" (also known as jagged arrays or Iliffe vector).

Multidimensional-arrays are often used to put values in a table format (e.g. rows and columns).

Tutorials:

This StackOverflow thread provides some insight on the difference between multi-dimensional arrays and jagged arrays in C#.

Wikipedia article.

35247 questions
5
votes
2 answers

Algorithm for creating multi-dimensional array

I'm using PHP and I need help with a seemingly simple task with an array. This is my example array: $arr = array( 0 => NULL, 1 => NULL, 2 => NULL, 3 => NULL, 8 => '2', 9 => '2', 10 => '2', 11 => '2', 12 =>…
user367217
  • 499
  • 2
  • 6
  • 20
5
votes
1 answer

How to get key of multidimensional array in foreach loop using php?

I need to print the student name and the mark from the following array for a given subject: $marks = [ "john" => ["physics" => 30, "maths" => 55, "chemistry" => 66], "jack" => ["physics" => 44, "maths" => 19, "chemistry" => 87], "mark"…
JohnSnow
  • 163
  • 4
  • 16
5
votes
4 answers

Create an array where each element stores its indices

I want to create a 2d numpy array where every element is a tuple of its indices. Example (4x5): array([[[0, 0], [0, 1], [0, 2], [0, 3], [0, 4]], [[1, 0], [1, 1], [1, 2], [1, 3], …
ovs
  • 173
  • 2
  • 11
5
votes
1 answer

Get/sort next multi-dimensional array element dynamically

I'm running through a great old brain fart currently and am stuck dynamically selecting the next "round match" that the winners of the below rounds will advance to: The ladder above is dynamically generated, and what I'd like to do is figure out…
Darren
  • 13,050
  • 4
  • 41
  • 79
5
votes
7 answers

How to deep copy an irregular 2D array

How can I deep copy an irregularly shaped 2D array in Java? Ie. int[][] nums = {{5}, {9,4}, {1,7,8}, {8,3,2,10}} I'm unable to use Arrays.arrayCopy() for some reason (versioning?)
Sean McDaid
  • 71
  • 1
  • 2
  • 7
5
votes
1 answer

How to subset data using multidimensional coordinates using python xarray?

I have a netcdf file that uses multidimensional coordinates. My xarray dataset looks like this Dimensions: (Time: 48, bottom_top: 50, bottom_top_stag: 51, soil_layers_stag: 4, south_north: 1015, south_north_stag: 1016,…
5
votes
1 answer

find smallest number in array javascript

What would be the most efficient way to take n smallest numbers from Array in Javascript [[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]] Result is [1,13,32,1]
user7423927
5
votes
1 answer

Using wildcards when accessing a multi-dimensional object in Javascript

I'm working with a GeoJSON dataset that is formatted like this: { "type": "Feature", "properties": { "startcong": "109", "district": "7", "statename": "Pennsylvania", "member": { "112": { "21168": { …
Cameron Scott
  • 1,276
  • 2
  • 17
  • 37
5
votes
4 answers

How to merge two arrays in JavaScript and keep their order

I had an whiteboard task that stumped me in the interview, however I have written a solution and wondered if anyone has improvements on it as I'm iterating which the interviewer said not to. The two arrays must be merged with the order being…
azz0r
  • 3,283
  • 7
  • 42
  • 85
5
votes
6 answers

How do I implement nested ArrayList?

I want to implement a data structure which looks something like this. {{RowID, N1, N2, N3}, {RowID, N4, N5, N6}, {RowID, N7, N8, N9}} And goes on. It basically is a table in Java with 3 columns and RowID. What data structure should I use and how…
js0823
  • 1,843
  • 8
  • 24
  • 36
5
votes
2 answers

Lisp: multidimensional array elementwise operations

What is the "correct" construct in Common Lisp to apply elementwise operations to multidimensional arrays? The following examples should help illustrate what I'm trying to do: A) Suppose I want to increase every element of an array by one: 0 1 2 …
Nick Alger
  • 984
  • 7
  • 26
5
votes
1 answer

Multi-dimensional char array (array of strings) in python ctypes

I'm trying to pass an array of character arrays to a C function using ctypes. void cfunction(char ** strings) { strings[1] = "bad"; //works not what I need. strings[1][2] = 'd'; //this will segfault. return; } char *input[] =…
user17925
  • 989
  • 2
  • 10
  • 20
5
votes
1 answer

Implementing GetSlice for slicing in F# interface

F# supports "slice expressions", which e.g. for a conventional one-dimensional array myArray allows for expressions such as myArray.[3 .. 5]. According to e.g. the F# 4.0 language specification (section 6.4.7), this is implemented by calling a…
5
votes
1 answer

the difference between [,] and [][] in C#

I am currently trying to learn C#, and I ran across following question: What is the difference between [,] and [][] in a type in C#?
CodenameLambda
  • 1,486
  • 11
  • 23
5
votes
3 answers

Return Multidimensional Array From Function

I encountered some issue in converting my existing vbs script to PowerShell script. I have illustrate here with some dummy codes instead of my original code. In example 1, I only have 1 set of elements in the array, upon return the array variable…