Search Results

Search found 483 results on 20 pages for 'multidimensional'.

Page 9/20 | < Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >

  • Create an grid array...

    - by Anicho
    Okay so I am looking to create a grided array in OGRE3D game engine but the array is generic my array skills are pretty basic and need work so I am posting this just to be sure I am doing this correctly. #define GRIDWIDTH 10 #define GRIDHEIGHT 10 int myGrid [HEIGHT][WIDTH]; int n,m; int main () { for (n=0;n<HEIGHT;n++) for (m=0;m<WIDTH;m++) { jimmy[n][m]=(n+1)*(m+1); } return 0; } I am assuming the above will return: 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 Then I can assign each point in the array to a valid node in OGRE3D to create a grid in 3D view would this work? Just need to tell me if I am doing it right or wrong dont need the ogre3d code....

    Read the article

  • PHP multi dimensional array manipulation

    - by atif089
    Hi, This is my array Array ( [0] => Array ( [sample_id] => 3 [time] => 2010-05-30 21:11:47 ) [1] => Array ( [sample_id] => 2 [time] => 2010-05-30 21:11:47 ) [2] => Array ( [sample_id] => 1 [time] => 2010-05-30 21:11:47 ) ) And I want to get all the sample_ids in one array. can someone please help ? Can this be done without for loops (because arrays are very large).

    Read the article

  • Multi-dimensional array edge/border conditions

    - by kirbuchi
    Hi, I'm iterating over a 3 dimensional array (which is an image with 3 values for each pixel) to apply a 3x3 filter to each pixel as follows: //For each value on the image for (i=0;i<3*width*height;i++){ //For each filter value for (j=0;j<9;j++){ if (notOutsideEdgesCondition){ *(**(outArray)+i)+= *(**(pixelArray)+i-1+(j%3)) * (*(filter+j)); } } } I'm using pointer arithmetic because if I used array notation I'd have 4 loops and I'm trying to have the least possible number of loops. My problem is my notOutsideEdgesCondition is getting quite out of hands because I have to consider 8 border cases. I have the following handled conditions Left Column: ((i%width)==0) && (j%3==0) Right Column: ((i-1)%width ==0) && (i>1) && (j%3==2) Upper Row: (i<width) && (j<2) Lower Row: (i>(width*height-width)) && (j>5) and still have to consider the 4 corner cases which will have longer expressions. At this point I've stopped and asked myself if this is the best way to go because If I have a 5 line long conditional evaluation it'll not only be truly painful to debug but will slow the inner loop. That's why I come to you to ask if there's a known algorithm to handle this cases or if there's a better approach for my problem. Thanks a lot.

    Read the article

  • PHP: Modifying array recursively?

    - by Industrial
    Hi everybody, I have tried to make a function that iterates through the following array to flatten it and add parent id to children, where applicable. I just can't make it work, so I hope that anyone here has an idea of what to do: Here's the starting point: Array ( [0] => Array ( [id] => 1 ) [1] => Array ( [id] => 2 [children] => Array ( [0] => Array ( [id] => 3 ) ) ) ) The expected result : Array ( [0] => array ( [id] => 1 ) [1] => array ( [id] => 2 ) [2] => array ( [id] => 3, [parent] => 2 ) ) Hope that anyone can point me in the right direction. Thanks a lot!

    Read the article

  • How to structurally display a multi-dimensional array in PHP?

    - by Jaime Cross
    How can I display the contents of an array as follows: Company Name - Username1 - Username2 Another Company Name - Username3 The array I have created is as follows: $array[1]['company_id'] = '12'; $array[1]['company_name'] = 'ABC Company'; $array[1]['company_type'] = 'default'; $array[1]['user_id'] = '23'; $array[1]['user_name'] = 'Andrew'; $array[2]['company_id'] = '12'; $array[2]['company_name'] = 'ABC Company'; $array[2]['company_type'] = 'default'; $array[2]['user_id'] = '27'; $array[2]['user_name'] = 'Jeffrey'; $array[3]['company_id'] = '1'; $array[3]['company_name'] = 'Some Company'; $array[3]['company_type'] = 'default'; $array[3]['user_id'] = '29'; $array[3]['user_name'] = 'William'; $array[4]['company_id'] = '51'; $array[4]['company_name'] = 'My Company'; $array[4]['company_type'] = 'default'; $array[4]['user_id'] = '20'; $array[4]['user_name'] = 'Jaime';

    Read the article

  • from one-dimensional to two-dimensional array

    - by Thijs
    Hi again, I have this PHP one dimensional array: Array ( [Female--N] => 11 [Male--N] => 11 [Humans--N] => 11 [Adult--N] => 8 [Adolescent--N] => 8 [Reaction Time-physiology--N] => 6 [Acoustic Stimulation-methods--N] => 6 [Schizophrenia-genetics--Y] => 5 [Motion Perception--N] => 3 ) And i want a new array from this that looks like (i think this tow-dimensional..?): Array ( [Female][N] => 11 [Male][N] => 11 [Humans][N] => 11 [Adult][N] => 8 [Adolescent][N] => 8 [Reaction Time-physiology][N] => 6 [Acoustic Stimulation-methods][N] => 6 [Schizophrenia-genetics][Y] => 5 [Motion Perception][N] => 3 ) Can i use split method on key elements? Little bit harder... i also need to split on the single '_' underscore, i did this to prevent the columns getting mixed up... But the example below doesn't do the job right... $new_array = array(); foreach($MeshtagsArray as $key => $value) { $parts = explode('__', $key, 2); $parts2 = explode('_', $key, 2); $new_array[] = array( 'discriptor' => $parts[0], 'qualifier' => $parts2[1], 'major' => $parts[1], '#occurence' => $value ); So the output should be something like: [0] => Array ( [discriptor] => Female [qualifier] => [major] => N [#occurence] => 11 ........ [5] => Array ( [discriptor] => Reaction Time [qualifier] => physiology [major] => N [#occurence] => 6 Best regards, Thijs

    Read the article

  • jquery - array problem help pls.

    - by russp
    Sorry folks, I really need help with posting an array problem. I would imaging it's quite simple, but beyond me. I have this JQuery function (using sortables) $(function() { $("#col1, #col2, #col3, #col4").sortable({ connectWith: '.column', items: '.portlet:not(.ui-state-disabled)', stop : function () { serial_1 = $('#col1').sortable('serialize'); serial_2 = $('#col2').sortable('serialize'); serial_3 = $('#col3').sortable('serialize'); serial_4 = $('#col4').sortable('serialize'); } }); }); Now I can post it to a database like this, and I can loop this ajax through all 4 "serials" $.ajax({ url: "test.php", type: "post", data: serial_1, error: function(){ alert(testit); } }); But that is not what I want to do as it creates 4 rows in the DB table. I want/need to create a single "nested array" from the 4 serials so that it enters the DB as 1 (one) row. My "base" database data looks like this: a:4:{s:4:"col1";a:3:{i:1;s:6:"forums";i:2;s:4:"chat";i:3;s:5:"blogs";}s:4:"col2";a:2:{i:1;s:5:"pages";i:2;s:7:"members";}s:4:"col3";a:2:{i:1;s:9:"galleries";i:2;s:4:"shop";}s:4:"col4";a:1:{i:1;s:4:"news";}} Therefore the JQuery array should "replicate" and create it (obviously will change on sorting) Help please thanks in advance

    Read the article

  • Recursing data into a 2 dimensional array in PHP 5

    - by user315699
    I'm getting bamboozled by "for each" loops and two dimensional arrays, and I'm a php newb so please bear with me (and ignore any variables with the word "image" - it's all about the mp3s, I just didn't change it from the xml tutorial) I found a php function on the net that list files in a directory, the output of which is: Array ( [0] = audio/1.mp3 [1] = audio/2.mp3 [2] = audio/3.mp3 [3] = audio/4.mp3 [4] = audio/5.mp3 ) As expected. And another that lists some info about mp3 files. $mp3datafile = 'audio/1.mp3'; $m = new mp3file($mp3datafile); $mp3dataArray = $m-get_metadata(); print_r($mp3dataArray); unset($mp3dataArray); The output of which is Array ( [Filesize] = 31972 [Encoding] = CBR [etc] ) In order to automatically build RSS for a podcast, I need to generate XML for each item. So far so good. This is how I'm making the xml foreach ($imagearray as $key = $val) { $tnsoundfile = $xml_generator-addChild('item'); $tnsoundfile-addChild('title', $podcasttitle); $enclosure = $tnsoundfile-addChild('enclosure'); $enclosure-addAttribute('url', $val); // that's the filename $enclosure-addAttribute('length', $mp3dataArray[Filesize]); // << Length is file length, not time. But later I also need $mp3dataArray[Length mm:ss] for duration tag. $enclosure-addAttribute('type', 'audio/mpeg'); $tnsoundfile-addChild('guid', $path_to_image_dir.'/'.$val); } (The above has been truncated, I realise it's not proper xml right now, but it was just to show what was going on). Perfect. But I need to do it for as many files as there are in the directory. So, I have an array of the names of the files in the directory in $mp3data And, I have an array of mp3 data in $mp3dataArray from one iteration of the get_metadata() function. If I do the following, then I get a nice list of the mp3 data of the 5 files in the directory: foreach ($mp3data as $key = $val) { $mp3datafile = $val; $m = new mp3file($mp3datafile); $mp3dataArray = $m-get_metadata(); print_r($mp3dataArray); unset($mp3dataArray); } As expected. Where I'm struggling, and have been for most of the day in spite of reading many forums and tutorials, is how to populate the "second dimension" of the array, so that it goes through 1,2,3,4 and 5.mp3 (or however many there are), extracts the metadata, then allows me to use it in the xml section above. Here's what I have foreach ($mp3data as $key = $val) { $mp3datafile = $val; $m = new mp3file($mp3datafile); $mp3dataArray = $m-get_metadata(); $mp3testarray = array($mp3dataArray); } print_r($mp3dataArray); Shouldn't that line print_r($mp3dataArray); give me a nice list of 5 lots of mp3 data, in the way it did when I recursed through the loop as before? Cos this is driving me nuts! It must be something so simple, and any help would be greatly appreciated. Thank you in advance.

    Read the article

  • C# huge size 2-dim arrays

    - by 4eburek
    I need to declare square matrices in C# WinForms with more than 20000 items in a row. I read about 2GB .Net object size limit in 32bit and also the same case in 64bit OS. So as I understood the single answer - is using unsafe code or separate library built withing C++ compiler. The problem for me is worth because ushort[20000,20000] is smaller then 2GB but actually I cannot allocate even 700MB of memory. My limit is 650MB and I don't understand why - I have 32bit WinXP with 3GB of memory. I tried to use Marshal.AllocHGlobal(700<<20) but it throws OutOfMemoryException, GC.GetTotalMemory returns 4.5MB before trying to allocate memory. I found only that many people say use unsafe code but I cannot find example of how to declare 2-dim array in heap (any stack can't keep so huge amount of data) and how to work with it using pointers. Is it pure C++ code inside of unsafe{} brackets? Could you please provide a small example of working with matrices using pointers in unsafe code.

    Read the article

  • Get usable array from a curl response, which is formatted as a php array

    - by Mint
    $ch = curl_init("url"); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, "test"); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $outputArray = curl_exec($ch); Then $outputArray will contain: Array ( [0] => Array ( [r1] => test response [r2] => 4 [r3] => 32 ) ) So I would think PHP can see that it's an array and treat it as such, but when I do something like echo $outputCode[0][r_title]."\n"; it gives an error: PHP Fatal error: Cannot use string offset as an array in /www/test.php on line 75 (line 75 being the echo one just above) What am I doing wrong?

    Read the article

  • Ladder-like word game in Java

    - by sasquatch90
    I've found this question http://stackoverflow.com/questions/2844190/choosing-design-method-for-ladder-like-word-game and I would also like to do this kind of program. I've written some code but already have two issues. Here's what I already have : GRID : public class Grid { public Grid(){} public Grid( Element e ){} } ELEMENT : public class Element { final int INVISIBLE = 0; final int EMPTY = 1; final int FIRST_LETTER = 2; final int OTHER_LETTER = 3; private int state; private String letter; public Element(){} //empty block public Element(int state){ this("", 0); } //filled block public Element(String s, int state){ this.state = state; this.letter = s; } public static void changeState(int s){ } public int getState(){ return state; } public boolean equalLength(){ return true; } public boolean equalValue(){ return true; } @Override public String toString(){ return "["+letter+"]"; } } MAIN: import java.util.Scanner; public class Main { public static void main(String[] args){ Scanner sc = new Scanner(System.in); System.out.println("Height: "); while (!sc.hasNextInt()) { System.out.println("int, please!"); sc.next(); } final int height = sc.nextInt(); Grid[] game = new Grid[height]; for(int i = 1; i <= height; i++) { String s; do { System.out.println("Length " + i + ", please!"); s = sc.next(); } while (s.length() != i); Element[] line = new Element[s.length()+1]; Element single = null; String[] temp = null; //issue here temp = s.split(""); System.out.println("s.length: "+s.length()); System.out.println("temp.length: "+temp.length); // for(String str : temp){ System.out.println("str:"+str); } for (int k = 0 ; k < temp.length ; k++) { if( k == 0 ){ single = new Element(temp[k], 2); System.out.println("single1: "+single); } else{ single = new Element(temp[k], 3); System.out.println("single2: "+single); } line[k] = single; } for (Element l : line) { System.out.println("line:"+l); } //issue here game[i] = line; } // for (Grid g : game) { System.out.println(g); } } } And sample output for debug : Height: 3 Length 1, please! A s.length: 1 temp.length: 2 str: str:A single1: [] single2: [A] line:[] line:[A] Here's what I think it should work like. I grab a word from user. Next create Grid element for whole game. Then for each line I create Element[] array called line. I split the given text and here's the first problem. Why string.split() adds a whitespace ? You can see clearly in output that it is added for no reason. How can I get rid of it (now I had to add +1 to the length of line just to run the code). Continuing I'm throwing the splitted text into temporary String array and next from each letter I create Element object and throw it to line array. Apart of this empty space output looks fine. But next problem is with Grid. I've created constructor taking Element as an argument, but still I can't throw line as Grid[] elements because of 'incompatible types'. How can I fix that ? Am I even doing it right ? Maybe I should get rid of line as Element[] and just create Grid[][] ?

    Read the article

  • What methods are used to visualize a 4-dimensional Array?

    - by Atomiton
    An Array ( a row of elements ): [ ][ ][ ][ ][ ][ ] A 2-D Array ( a table ): [ ][ ][ ][ ][ ][ ] [ ][ ][ ][ ][ ][ ] [ ][ ][ ][ ][ ][ ] [ ][ ][ ][ ][ ][ ] A 3-D Array: //Imagine the above table as a cube ( a table with depth ) How does one visualize a 4-D array? The closest I can come is multiple cubes, so for int[,,,] [5,10,2,7] would be cube 5, row 10, column 2, layer(depth) 7. I'm not sure if this is the best way to visualize a 4-D array, though... and I'm not sure it's the best way to teach it... however it does have the advantage of being extensible ( a row cubes, a table of cubes, a cube of cubes ( 6-d array ) Cubes through time is another way that I can think of it. Am I on the right track here?

    Read the article

  • Draw a position from a 2d Array on respected canvas location

    - by Anon
    Background: I have two 2d arrays. Each index within each 2d array represents a tile which is drawn on a square canvas suitable for 8 x 8 tiles. The first 2d array represents the ground tiles and is looped and drawn on the canvas using the following code: //Draw the map from the land 2d array map = new Canvas(mainFrame, 20, 260, 281, 281); for(int i=0; i < world.length; i++){ for(int j=0; j < world[i].length; j++){ for(int x=0; x < 280; x=x+35){ for(int y=0; y < 280; y=y+35){ Point p = new Point(x,y); map.add(new RectangleObject(p,35,35,Colour.green)); } } } } This creates a grid of green tiles 8 x 8 across as intended. The second 2d array represents the position on the ground. This 2d array has everyone of its indexes as null apart from one which is comprised of a Person class. Problem I am unsure of how I can draw the position on the grid. I was thinking of a similar loop, so it draws over the previous 2d array another set of 64 tiles. Only this time they are all transparent but the one tile which isn't null. In other words, the tile where Person is located. I wanted to use a search throughout the loop using a comparative if statement along the lines of if(!(world[] == null)){ map.add(new RectangleObject(p,35,35,Colour.red));} However my knowledge is limited and I am confused on how to implement it.

    Read the article

  • multi-dimension array value sorting in php

    - by David
    Another potentially interesting (or n00b, whatever comes first) question. I am building up an array with a set of database fields with information about table, actual field name and descriptive field name as a multi-dimensional array. Here is what it currently looks like: $Fields['User']['ID'] = "User ID"; $Fields['User']['FirstName'] = "First Name"; $Fields['Stats']['FavouriteOrder'] = "Favourite Item Ordered"; $Fields['Geographic']['Location'] = "Current Location"; $Fields['Geographic']['LocationCode'] = "Current Location Code"; Okay, this is fine, but I am piping this into a system that allows exporting of selected fields, and in the end I want to foreach() through the different levels, extract the data and then ultimately have all the descriptive fields to be displayed sorted alphabetically using their descriptive name. So ultimately in the order: Current Location, Current Location Code, Favourite Item Ordered, First Name then User ID - obviously keeping index associations. I can't use usort() and I can't use array_multisort()... or maybe I can and I just don't know how. usort() seems to need a key to sort by, but I have variable keys. array_multisort() just seems to do the same as sort() really. Any ideas?

    Read the article

  • Newtonsoft.json throwing error: Array was not a one-dimensional array.

    - by SIA
    Hi everybody, I am getting an error when trying to serialize an object products. Product product = new Product(); product.Name = "Apple"; product.Expiry = new DateTime(2008, 12, 28); product.Price = 3.99M; product.Sizes = new string[3,2] { {"Small","40"}, {"Medium","44"}, {"Large","50"} }; string json = JsonConvert.SerializeObject(product);//this line is throwing an error Array was not a one-dimensional array Is there any way to serialize a two dimensional array with Newtonsoft.json Thanks in Advance. SIA

    Read the article

  • PHP 5.2 Function needed for GENERIC sorting FOLLOWUP

    - by donbriggs
    OK, you guys gave me a great solution for sorting a recordset array last Friday. (http://stackoverflow.com/questions/2884325/php-5-2-function-needed-for-generic-sorting-of-a-recordset-array) But now when I implement it, I end up with an extra element in the recordset array. I won't wast space reposting the same info, as the link is above. But the bottom line is that when I sort an array of 5 records, the resulting array has 6 records. The last element in the array is not a record array, but rather just a element containing an integer value of 1. I presume that it is somehow getting the output value of the "strnatcasecmp" function, but I have no idea how it is happening. Here is the function that you fine folks provided last week: function getSortCommand($field, $sortfunc) { return create_function('$var1, $var2', 'return '.$sortfunc.'($var1["'.$field.'"], $var2["' .$field .'"]);'); } And here is the line I am calling to sort the array: $trek[] = usort($trek, getSortCommand('name', 'strnatcasecmp')); This produces the following output, with an extra element tacked on to the end. Array ( [0] = Array ( [name] = Kirk [shirt] = Gold [assign] = Bridge ) [1] => Array ( [name] => McCoy [shirt] => Blue [assign] => Sick Bay ) [2] => Array ( [name] => Scotty [shirt] => Red [assign] => Engineering ) [3] => Array ( [name] => Spock [shirt] => Blue [assign] => Bridge ) [4] => Array ( [name] => Uhura [shirt] => Red [assign] => Bridge ) [5] => 1 )

    Read the article

  • Concatenate arrays items

    - by j.
    I have two arrays: x = [ [0, "#0"], [1, "#1"] ] y = [ [00, "00 description"], [10, "10 description"] ] What i need is to merge them so i get the following as result: result = [ [000, "#0 00 description"], [010, "#0 10 description"], [100, "#1 00 description"], [110, "#1 10 description"]] Is there a method for that? Or I'll need to use collect or something like this? Thanks in advance.

    Read the article

  • How can I extract values out of this array?

    - by Jagira
    Array ( [status] => success [abc] => Array ( [0] => Array ( [name] => John Doe [age] => 23) [1] => Array ( [name] => John Doe_1 [age] => 23) [2] => Array ( [name] => John Doe_2 [age] => 23) ) ) When I try foreach($stories as $story){ } It returns an error.

    Read the article

  • Best way to store 3 pieces of data as a single entry

    - by Matt
    For a game server, I want to record details when a player makes a kill, store this, and then at intervals update to a sql database. The part i'm interested in right now is the best method of storing the kill information. What i'd like to pass to the sql server on update would be {PlayerName, Kills, Deaths}, where the kills and deaths are a sum for the period between updates. So i'm assuming i'd build a list along the lines of {bob, 1, 0} {frank, 0, 1} {tom, 1, 0} {frank, 0, 1} then on update, consolidate the list to {frank, 14, 3}etc Can someone offer some advice please?

    Read the article

  • Mulit-dimensional array edge/border conditions

    - by kirbuchi
    Hi, I'm iterating over a 3 dimensional array (which is an image with 3 values for each pixel) to apply a 3x3 filter to each pixel as follows: //For each value on the image for (i=0;i<3*width*height;i++){ //For each filter value for (j=0;j<9;j++){ if (notOutsideEdgesCondition){ *(**(outArray)+i)+= *(**(pixelArray)+i-1+(j%3)) * (*(filter+j)); } } } I'm using pointer arithmetic because if I used array notation I'd have 4 loops and I'm trying to have the least possible number of loops. My problem is my notOutsideEdgesCondition is getting quite out of hands because I have to consider 8 border cases. I have the following handled conditions Left Column: ((i%width)==0) && (j%3==0) Right Column: ((i-1)%width ==0) && (i>1) && (j%3==2) Upper Row: (i<width) && (j<2) Lower Row: (i>(width*height-width)) && (j>5) and still have to consider the 4 corner cases which will have longer expressions. At this point I've stopped and asked myself if this is the best way to go because If I have a 5 line long conditional evaluation it'll not only be truly painful to debug but will slow the inner loop. That's why I come to you to ask if there's a known algorithm to handle this cases or if there's a better approach for my problem. Thanks a lot.

    Read the article

< Previous Page | 5 6 7 8 9 10 11 12 13 14 15 16  | Next Page >