multidimensional-array

Reading a file into a multidimensional array

I want to read in a grid of numbers (n*n) from a file and copy them into a multidimensional array, one int at a time. I have the code to read in the file and print it out, but dont know how to take each int. I think i need to splitstring method and a blank delimiter "" in order to take every charcter, but after that im not sure. I would ...

How should I design an data table that has six or more variables?

The situation is akin to the following: Assume I am a store selling fruits, I would like to record the costs of each type of fruit. Assume the customer has specific tastes, and they can differenciate everything. A fruit can be an orange, apple, pear, or peach It could be n days fresh from the vendor The fruits come from different cou...

Generating a multiple list of combinations for a number in Java

The following is the problem I'm working on and my snippet of code. Is there a better way to implement this? I have used basic control structures for this below. Is it better to store the rows and columns in a map and searching through the map based on the key/value pairs? There is a security keypad at the entrance of a building. It...

PHP loop through array and split into seperate arrays.

Hi I have this PHP array of Amazon Sub Categories what I am trying to do is loop through the array and split into 3 seperate ones, Heres the Array, and needs to be split into 3 arrays $request, and all the children under it $subCats and final variable $Ancestors. The $subCats will contain all the [Children][BrowseNode]. Its driving m...

Accessing Dictionary and Multi-Dimension Array is Slow

I found that accessing Dictionary and Multi-Dimension array can be slow-- quite a puzzle since access time for dictionary and array is O(1). This is my code public struct StateSpace { public double q; public double v; public double a; } public class AccessTest { public Dictionary<int, Dictionary<double,StateSpace>> ModeStateSpace; ...

looping through a multi-dimensional array in Smarty

I have a multi-dimensional array generated in PHP: array( 'Requirements' => array( 'export_requirements' => array('value'=> 1, 'label'=> 'Export'), 'add_requirements' => array('value'=> 2, 'label'=> 'Add'), 'add_private_requirements' => array('value'=> 4, 'label'=> 'Add Private...

How to sort a multi-dimensional XML file??

I have tried to get an XML file to sort and have had no luck. After a day and a-half, I need some help from an expert. Thanks. My XML File (shortened for the example): <?xml version="1.0" encoding="iso-8859-1"?> <deadlines> <deadline> <date>2010-06-01</date> <text>Application for Summer Due</text> </deadline> ...

Getting the array length of a 2D array in Java

I need to get the length of a 2D array for both the row and column. I’ve successfully done this, using the following code: public class MyClass { public static void main(String args[]) { int[][] test; test = new int[5][10]; int row = test.length; int col = test[0].length; System.out.println(row); System.out.println...

parsing/searching a beastly array filled with simple xml objects in php

Hi, So Im working on a Excel xml parsing class, and Im trying to search through an array of the header values of the file, to return the key integer. If I can get the key int, then I can grab an entire column by the value of the header in the file. I have tried using in_array, search_array and a bunch of other functions, but nothing is ...

Using Recursion to Flatten a PHP Array with Subitems Based on Values (Wasted an Hour on This!)

I'm trying to build a navigation menu. I am receiving an array with a structure like this: [ [ Title = A Sub items = [ Title = B Sub items = [ Title = C ] ] ], [ Title = A Sub items = [ Title = B Sub items = [ Title = D ] ] ], ] I need to take it and ...

Creating Multidimenional Arrays

How can I add arrays into an existing array item? For instance: $user[$user->id] = array(//values); But if that user needs another array added, I want all data to fall under that user ID in the array. I want to store orders a user has made, so I can look up all orders on the fly by user ID in the $user array above. ...

Why is this giving me a segfault?

This: bool grid[1280][1024]; for (int x = 0; x<1280; x++) { for (int y = 0; y<1024; y++) { grid[x][y] = false; } } works fine, but bool grid[1280][1024]; bool grid2[1280][1024]; for (int x = 0; x<1280; x++) { for (int y = 0; y<1024; y++) { grid[x][y] = false; grid2[x][y] = false; } } ...

Python: I am unable to comprehend the concept of a For Loop, apparently.

I've got a list of 400 numbers, and i want to but them in a 20x20 grid using Python. I've made a "2d array" (not really because Python doesn't support them, I've had to use a list of lists.) When i try to loop through and assign each subsequnt item to the next box in the grid, it fails. i end up assinging the last item in the list to ...

array of ByteArray into MemoryStream

I have a method which returns a array of ByteArray: public byte[][] Draw(ImageFormat imageFormat, ImageSize imageSize); and I need to write it into a MemoryStream: var byteArray = instanceName.Draw(ImageFormat.Jpeg, ImageSize.Dpi150); MemoryStream ms = new MemoryStream(byteArray[0]); This is working so far because the array of byte...

difficulty modifying two dimensional ruby array

Hi there, Excuse the newbie question. I'm trying to create a two dimensional array in ruby, and initialise all its values to 1. My code is creating the two dimensional array just fine, but fails to modify any of its values. Can anyone explain what I'm doing wrong? def mda(width,height) #make a two dimensional array a = Ar...

Dynamic Contiguous 3D arrays in C

I'm trying to implement dynamically allocated contiguous 3D arrays in a C code. The arrays must be contiguous because I'm relying on netCDF output of the arrays. Now I adapted a solution posted here Stack OverFlow Solution. This works fine for dynamically allocating the arrays and indexing them...however, when netCDF outputs them ther...

PHP explode and put into array

Hello, I have this line of string Fruits-banana|apple|orange:Food-fries|sausages:Desserts-ice cream|apple pie the : (colon) is the separator for the main topic, and the | is the separator for the different type of sub topics. I tried to explode it out and put it into array, I need the result to be something like this to be displayed...

Passing/modifying multidimensional array to function in C

I haven't used C in 5-6 years, and feel that this is probably a really obvious answer. I thought that arrays were passed by reference automatically in C, so my code below should modify the values of the array created in main() within the change function. It changes the values of the local variable within the change function, but this is...

Why am I getting an ArrayIndexOutOfBounds exception?

private void equal_AxB() { int x = matrix_A.length; int y = matrix_B[0].length; matrix_C = new double[x][y]; for(int i = 0; i < x; i++) { for(int j = 0; j < y; j++) { for(int k = 0; k < y; k++){ matrix_C[i][j] += matrix_A[i][k]*matrix_B[k][j]; } } } return; ...

passing a multidimensional array from one activity to another

How can I pass a multidimensional array from one activity to another? ...