multidimensional-array

Accessing the content of a variable array with ctypes.

Hi there, I use ctypes to access a file reading C function in python. As the read data is huge and unknown in size I use **float in C . int read_file(const char *file,int *n_,int *m_,float **data_) {...} The functions mallocs an 2d array, called data, of the appropriate size, here n and m, and copies the values to the referenced ones...

Game Development - Array with pointers to array elements

I am currently developing a game for the iPhone/iPod/iPad. To store the board data, which is 12 columns by 8 rows, I have an array that stores pointers to one of the game items, a block. It is declared as follows: BlockData* mBoard[kNumberOfColumns][kNumberOfRows]; I also have another array declared like this: BlockData* mCenterSqu...

sorting 2D arrays in Objective C

Hi Folks, I'm stuck with sorting 2D arrays in objective c. I have a 2D array which I made from two string arrays. NSArray *totalRatings = [NSArray arrayWithObjects:namesArray,ratingsArray,nil]; I've pulled the values using: for (int i=0; i<2; i++) { for (int j=0; j<5; j++) { NSString *strings = [[totalRatings objectAtIndex:i] ...

A better php array_merge

Hi, I am looking to do this a better way without the need to hardcode the integers for $justPrices[$i]: $pricesResult = array_merge($justPrices[0], $justPrices[1], $justPrices[2], $justPrices[3]); $justPrices is a multidimensional array, containing 4 'bands' of prices within each array. The data for $justPrices being for example: Ar...

Read flat list into multidimensional array/matrix in python

I have a list of numbers that represent the flattened output of a matrix or array produced by another program, I know the dimensions of the original array and want to read the numbers back into either a list of lists or a NumPy matrix. There could be more than 2 dimensions in the original array. e.g. data = [0, 2, 7, 6, 3, 1, 4, 5] sha...

Php Sorting a multi-dimensional array by field name

Hello I have tried adapting this code to use to sort a multidimensional array on a named key/field. The field is an integer what I need to sort smallest to biggest. function myCmp($a, $b) { return strcmp($a["days"], $b["days"]); } uasort($myArray, "myCmp"); This sorts the arrays as I need but in the wrong order. At the moment it ...

Practical use of N-Dimensional Arrays,where (N>3)

I have been programming for the last 8 years and now I was just wondering that if there is any practical use of N-Dimensional array,where N>3.I can only visualize of a data structure that is less than or equal to 3 dimensions.Has any one used more than 3 dimensions in any program?Are there any practical uses of a N-D array which is beyo...

Java ArrayList of Arrays?

I want to create a mutli dimensional array without a fixed size. I need to be able to add items of String[2] to it. I have tried looking at: private ArrayList<String[]> action = new ArrayList<String[2]>(); but that doesn't work. does anyone have any other ideas? ...

Search inside arrays, count, find duplicates, compare

Several HOW TO questions about simple and multidimensional arrays: 1) How to search in simple and multi arrays? 2) How to count number of search results? 3) How to catch duplicates inside: 3.1 multidimensional array? 3.2 simple array? 3.3 in array's search results? 3.4 and remove them? 4) How to compare two arrays (multidime...

Appending/creating/removing items from a javascript array, ideas??

Hi, I have a requirement whereby I have two panes on a page, the pane on the left holds a series of records specific to a option selected from a drop down. Each record has a plus sign next to it, if this is pressed it will be 'moved' to the right hand pane and displayed under the option the user selected. Multiple records can be put i...

Looping through a multidimensional array in php

i have this multidimensional array in php and I need be able to access all the elements including the first element "Computers". I need to turn this array into two arrays and i used this loop $i = 0; $left = array(); $right = array(); foreach ($all_products as $product) { if ($i++ % 2 == 0) { $left[] = $product; ...

looping through an array and grabbing the keys

Array ( [Screens] => Array ( [0] => Array ( [ SPKRS ] => Array ( [price] => 455 [quantity] => 3 [image] => ) ) ) [Software] => Array ( [0] => Array ( [Pricing] => Array ( [price] => 2 ...

this line is overwriting the array

ok so i am creating a multidementional array and this line only allows one element into it. How do i check to see if $related[$row_r['Category_name']][$row_r['name']] is greater then 0 and if so dont overwrite the value and just append onto it while($row_r = mysql_fetch_assoc($result)){ $related[$row_r['Category_name']][$row_r['na...

How do i get passed an empty key in a php array

how to i get to the arrays content if it doesnt have a key like this $products[0] this will get me partially there but how to i get past [] ( [0] => Array ( [] => Array ( [0] => Array ( [product_name] => stuff i need to get to ) ...

calucating the total of the price field in an array

( [0] => Array ( [0] => Array ( [0] => Array ( [price] => 76 ) [1] => Array ( [price] => 200 ) [2] => Array ( [price] => 500 ) [3] => Array ( [price] => 67 ) is there a clean way to calculate all these prices ...

Building a multidimensional associative array using PHP and MYSQL

Hi all, I'm trying to build a multidimensional associative array while fetching the results from a MySQL query. But i can't figure out how to achieve this. I want to build an array like this one: array ("cat_name" => "category1", "id_cat" => "1", "sub_cat" => array ("name_sub_cat" => "subCategory", "id_sub_cat" => "4", "ss_c...

using eval in PHP with multidimensional array

Hello, I have a array that I am writing to a file using var_export(). I reload the array every time the script starts. However, whenever I try to reference a variable inside the array it returns 'a', I can do a print_r() and see the array just fine, I just can not access the variable I want. Here is the saved output: array ( 'timesta...

unset a element of an array via reference

I can access anywhere inside the multi-dimensional an array via reference method. And I can change the its value. For example: $conf = array( 'type' => 'mysql', 'conf' => array( 'name' => 'mydatabase', 'user' => 'root', 'pass' => '12345', 'host' => array( '127.0...

Optimized "Multidimensional" Arrays in Ruby

From birth I've always been taught to avoid nested arrays like the plague for performance and internal data structure reasons. So I'm trying to find a good solution for optimized multidimensional data structures in Ruby. The typical solution would involve maybe using a 1D array and accessing each one by x*width + y. Ruby has the abili...

Slice a 2D Python Array

I have a 2d array in the numpy module that looks like: data = array([[1,2,3], [4,5,6], [7,8,9]]) I want to get a slice of this array that only includes certain columns of element. For example I may want columns 0 and 2: data = [[1,3], [4,6], [7,9]] What is the most Pythonic way to do thi...