multi-dimensional

Efficiently shrinking a two dimensional array in C#

What is an efficient way to shrink a two dimensional array to a smaller size in C#? For example: var bigArray = new object[100, 100]; var smallArray = new object[10, 10]; bigArray[0, 0] = 1; bigArray[0, 1] = 2; ... bigArray[99, 99] = 100000; startRowIndex = 0; startColumnIndex = 0; endRowIndex = 9; endColumnIndex = 9; smallArray = ...

Why does C# Multidimensional arrays not implement IEnumerable<T> ?

I have just noticed that a multidimensional array in C#, does not implement IEnumerable<T>, while it does implement IEnumerable. For single-dimensional arrays, both IEnumerable<T> and IEnumerable is implemented. Why this difference ? If a multi-dimensional array is IEnumerable, surely it should also implement the generic version ? I no...

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?) Thanks ...

How to "flatten" a multi-dimensional array to simple one in php?

It's probably beginner question but I'm going through documentation for longer time already and I can't find any solution. I thought I could use implode for each dimension and then put those strings back together with str_split to make new simple array. However I never know if the join pattern isn't also in values and so after doing str_...

How do I best process my multi-dimensional arrays in PHP?

I have an app that shows store sales. It is a multi-dimensional array, so each value in the root array is an array containing [sales], [cost], [date], etc. for the given day it pertains to. OK, there are 2 arrays for each store. One is for verified numbers and the next is for unverified numbers. The unverified picks up right after the ve...

How to create mutlidimensional list for this in C#?

Hi, I got a table (in file) which I split into blocks by spaces. I need structure like this: ----------------------------- |21|22|23|33|3323| |32|32| |434433|545454|5454| ------------------------------ It's more like each row is its own table. How should I do this? I tried List<List<string>> matrix = new List<List<string>>(); but I...

Is a kd-tree suitable for 4D space-time data (x,y,z,time)?

I want to use a data structure for sorting space-time data (x,y,z,time). Currently a processing algorithm searches a set of 4D (x,y,z,time) points, given a spherical (3d) spacial radius and a linear (1d) time radius, marking for each point, which other points are within those radii. The reason is that after processing, I can ask any 4D ...

Sort Array of MultiDiminsional Arrays on More Than One "Column" (Key) With Specified Sort Options

I'm looking to be able to sort an array of multi-dimensional arrays on more than one column. To further complicate it I'd like to be able to set specific sort options per key/column. I have what is similar the result of a DB query, but doesn't actually come from one, therefore the need to sort it in PHP rather than SQL. Array ( [0] ...

How to split a multidimensional array in PHP?

How can I take a multi-dimensional array like the below, and split it into multiple separate arrays? Additional challenge: Although I know there are two pairs in the example below (pageviews, visits), how can you do it assuming that you don't know the number of pairs in the array? For example, I may want to add "time on page" or "pages v...

Multi-dimensional filter to eliminate "bad" items from a large table?

I have a large table of N items with M (M>=3) distinct properties per item, From this table I have to remove all items for which the same table contains an item that scores equal or better on all properties. I have an algorithm (python) that solves it already, but it is output-sensitive and has a worst case of approx. O((n²+n)/2) when n...

PHP - how to flip the rows and columns of a 2D array

Normally I'd be asking how to turn something like this: 1 2 3 4 5 6 7 8 9 10 11 12 Into this: 1 4 7 10 2 5 8 11 3 6 9 12 But actually I want to turn it into this: 1 5 9 2 6 10 3 7 11 4 8 12 In other words, I want to flip the rows and columns, but keep...

PHP best way to MD5 multi-dimensional array?

Hi, i was wondering what is the best way to generate an MD5 (or any other hash) of a multi-dimensional array? I could easily write a loop which would traverse through each level of the array, concatenating each value into a string, and simply performing the MD5 on the string. However, this seems cumbersome at best and i wondered if t...

PHP: Iterating through array?

Hi, What I want, is a function that searches through my array, and returns all the children to a specific node. What is the most appropriate way to do this? Will recursion be necessary in this case? I have previously constructed a few quite complex functions that iterates with or without the help of recursion through multi-dimensiona...