Search Results

Search found 15255 results on 611 pages for 'sparse array'.

Page 37/611 | < Previous Page | 33 34 35 36 37 38 39 40 41 42 43 44  | Next Page >

  • How can we make a single dimension array to multidimensional Hierarchical ?

    - by Chetan sharma
    I have an single array of Hierarchical categories. Index of the array is the category_id like:: [8846] => Array ( [category_id] => 8846 [title] => Tsting two [description] => Tsting two [subtype] => categories [type] => object [level] => 2 [parent_category] => 8841 [tags] => new [name] => Tsting two ) each value has its parent_category value, I have around 500 elements in the array, what is the best way to make it. Process i followed: krsort categories array, so that all the child categories are at the beginning, then function makeHierarchical() { foreach($this->categories as $guid => $category) { if($category['level'] != 1) $this->multilevel_categories[$category['parent_category']][$guid] = $category; } } but this is not working, it does it only for first level. Can someone point out me the error.

    Read the article

  • why my array is losing it's contents when I refresh the page?

    - by Fernando SBS
    I have created an: var checkboxFarm = new Array(); then I want to record a checkbox status in that array, as there are 11 checkboxes. Button.addEventListener("click", function() { rp_farmAtivada(index); }, false); when clicked change the variable in the array: function rp_farmAtivada(index) { checkboxFarm[index] = !checkboxFarm[index]; }; but every time I refresh the page it loses all the checkboxes status and I'm aware that all that array gets the "undefined" value. the checkboxFarm array is defined in the beginning of the script, so it should have a global scope. Am I missing something?

    Read the article

  • How do I convert a Python list of lists of lists into a C array by using ctypes?

    - by pc05
    As seen here How do I convert a Python list into a C array by using ctypes? this code will take a python array and transform it to a C array. import ctypes arr = (ctypes.c_int * len(pyarr))(*pyarr) Which would the way of doing the same with a list of lists or a lists of lists of lists? For example, for the following variable list3d = [[[40.0, 1.2, 6.0, 0.3], [50.0, 4.2, 0, 0]], [[40.0, 1.2, 6.0, 0.3], [50.0, 4.2, 0, 0]], [[40.0, 1.2, 6.0, 0.3], [50.0, 4.2, 0, 0]]] I have tried the following with no luck: ([[ctypes.c_double * 4] *2]*3)(*list3d) # *** TypeError: 'list' object is not callable (ctypes.c_double * 4 *2 *3)(*list3d) # *** TypeError: expected c_double_Array_4_Array_2 instance, got list Thank you! EDIT: Just to clarify, I am trying to get one object that contains the whole multidimensional array, not a list of objects. This object's reference will be an input to a C DLL that expects a 3D array.

    Read the article

  • How do I return the indices of a multidimensional array element in C?

    - by Eddy
    Say I have a 2D array of random boolean ones and zeroes called 'lattice', and I have a 1D array called 'list' which lists the addresses of all the zeroes in the 2D array. This is how the arrays are defined: define n 100 bool lattice[n][n]; bool *list[n*n]; After filling the lattice with ones and zeroes, I store the addresses of the zeroes in list: for(j = 0; j < n; j++) { for(i = 0; i < n; i++) { if(!lattice[i][j]) // if element = 0 { list[site_num] = &lattice[i][j]; // store address of zero site_num++; } } } How do I extract the x,y coordinates of each zero in the array? In other words, is there a way to return the indices of an array element through referring to its address?

    Read the article

  • How to make an mutable C array for this data type?

    - by mystify
    There's this instance variable in my objective-c class: ALuint source; I need to have an mutable array of OpenAL Sources, so in this case probably I need a mutable C-array. But how would I create one? There are many questions regarding that: 1) How to create an mutable C-array? 2) How to add something to that mutable C-array? 3) How to remove something from that mutable C-array? 4) What memory management pitfalls must I be aware of? Must i free() it in my -dealloc method? And yes, I think this is something for the nice community wiki...

    Read the article

  • Sparse parameter selection using Genetic Algorithm

    - by bgbg
    Hello, I'm facing a parameter selection problem, which I would like to solve using Genetic Algorithm (GA). I'm supposed to select not more than 4 parameters out of 3000 possible ones. Using the binary chromosome representation seems like a natural choice. The evaluation function punishes too many "selected" attributes and if the number of attributes is acceptable, it then evaluates the selection. The problem is that in these sparse conditions the GA can hardly improve the population. Neither the average fitness cost, nor the fitness of the "worst" individual improves over the generations. All I see is slight (even tiny) improvement in the score of the best individual, which, I suppose, is a result of random sampling. Encoding the problem using indices of the parameters doesn't work either. This is most probably, due to the fact that the chromosomes are directional, while the selection problem isn't (i.e. chromosomes [1, 2, 3, 4]; [4, 3, 2, 1]; [3, 2, 4, 1] etc. are identical) What problem representation would you suggest? P.S If this matters, I use PyEvolve.

    Read the article

  • finding ALL cycles in a huge sparse matrix

    - by Andy
    Hi there, First of all I'm quite a Java beginner, so I'm not sure if this is even possible! Basically I have a huge (3+million) data source of relational data (i.e. A is friends with B+C+D, B is friends with D+G+Z (but not A - i.e. unmutual) etc.) and I want to find every cycle within this (not necessarily connected) directed graph. I've found this thread (http://stackoverflow.com/questions/546655/finding-all-cycles-in-graph/549402#549402) which has pointed me to Donald Johnson's (elementary) cycle-finding algorithm which, superficially at least, looks like it'll do what I'm after (I'm going to try when I'm back at work on Tuesday - thought it wouldn't hurt to ask in the meanwhile!). I had a quick scan through the code of the Java implementation of Johnson's algorithm (in that thread) and it looks like a matrix of relations is the first step, so I guess my questions are: a) Is Java capable of handling a 3+million*3+million matrix? (was planning on representing A-friends-with-B by a binary sparse matrix) b) Do I need to find every connected subgraph as my first problem, or will cycle-finding algorithms handle disjoint data? c) Is this actually an appropriate solution for the problem? My understanding of "elementary" cycles is that in the graph below, rather than picking out A-B-C-D-E-F it'll pick out A-B-F, B-C-D etc. but that's not the end of the world given the task. E / \ D---F / \ / \ C---B---A d) If necessary, I can simplify the problem by enforcing mutuality in relations - i.e. A-friends-with-B <== B-friends-with-A, and if really necessary I can maybe cut down the data size, but realistically it is always going to be around the 1mil mark. z) Is this a P or NP task?! Am I biting off more than I can chew? Thanks all, any help appreciated! Andy

    Read the article

  • Make an array of two.

    - by marharépa
    Hello! I'd like to make an array which tells my site's pages where to show in PHP. In $sor["site_id"] i've got two or four chars-lenght strings. example: 23, 42, 13, 1 In my other array (called to $pages_show) i want to give all the site_ids to an other id. $parancs="SELECT * FROM pages ORDER BY id"; $eredmeny=mysql_query($parancs) or die("Hibás SQL:".$parancs); while($sor=mysql_fetch_array($eredmeny)) { $pages[]=array( "id"=>$sor["id"], "name"=>$sor["name"], "title"=>$sor["title"], "description"=>$sor["description"], "keywords"=>$sor["keywords"] ); // this makes my pages array with the information about that page. $shower = explode(", ",$sor["site_id"]); // this is explode my site_id $pages_show[]=array( "id"=>$sor["id"], "where"=>$shower //to 'where' i want to put all the explode's elements one-by-one, to get the result like down ); This script gives me the following result: Array (3) 0 => Array (2) id => "29" where => Array (2) 0 => "17" 1 => "16" 1 => Array (2) id => "30" where => Array (1) 0 => "17" 2 => Array (2) id => "31" where => Array (1) 0 => "17" But in this case I'd like to be this: Array (4) 0 => Array (2) id => "29" where => "17" 1 => Array (2) id => "29" where => "16" 2 => Array (2) id => "30" where => "17" 3 => Array (2) id => "31" where => "17" Thanks for your help.

    Read the article

  • Problems with 3D Array for Voxel Data

    - by Sean M.
    I'm trying to implement a voxel engine in C++ using OpenGL, and I've been working on the rendering of the world. In order to render, I have a 3D array of uint16's that hold that id of the block at the point. I also have a 3D array of uint8's that I am using to store the visibility data for that point, where each bit represents if a face is visible. I have it so the blocks render and all of the proper faces are hidden if needed, but all of the blocks are offset by a power of 2 from where they are stored in the array. So the block at [0][0][0] is rendered at (0, 0, 0), and the block at 11 is rendered at (1, 1, 1), but the block at [2][2][2] is rendered at (4, 4, 4) and the block at [3][3][3] is rendered at (8, 8, 8), and so on and so forth. This is the result of drawing the above situation: I'm still a little new to the more advanced concepts of C++, like triple pointers, which I'm using for the 3D array, so I think the error is somewhere in there. This is the code for creating the arrays: uint16*** _blockData; //Contains a 3D array of uint16s that are the ids of the blocks in the region uint8*** _visibilityData; //Contains a 3D array of bytes that hold the visibility data for the faces //Allocate memory for the world data _blockData = new uint16**[REGION_DIM]; for (int i = 0; i < REGION_DIM; i++) { _blockData[i] = new uint16*[REGION_DIM]; for (int j = 0; j < REGION_DIM; j++) _blockData[i][j] = new uint16[REGION_DIM]; } //Allocate memory for the visibility _visibilityData = new uint8**[REGION_DIM]; for (int i = 0; i < REGION_DIM; i++) { _visibilityData[i] = new uint8*[REGION_DIM]; for (int j = 0; j < REGION_DIM; j++) _visibilityData[i][j] = new uint8[REGION_DIM]; } Here is the code used to create the block mesh for the region: //Check if the positive x face is visible, this happens for every face //Block::VERT_X_POS is just an array of non-transformed cube verts for one face //These checks are in a triple loop, which goes over every place in the array if (_visibilityData[x][y][z] & 0x01 > 0) { _vertexData->AddData(&(translateVertices(Block::VERT_X_POS, x, y, z)[0]), sizeof(Block::VERT_X_POS)); } //This is a seperate method, not in the loop glm::vec3* translateVertices(const glm::vec3 data[], uint16 x, uint16 y, uint16 z) { glm::vec3* copy = new glm::vec3[6]; memcpy(&copy, &data, sizeof(data)); for(int i = 0; i < 6; i++) copy[i] += glm::vec3(x, -y, z); //Make +y go down instead return copy; } I cannot see where the blocks may be getting offset by more than they should be, and certainly not why the offsets are a power of 2. Any help is greatly appreciated. Thanks.

    Read the article

  • php getting unique values of a multidimensional array

    - by Mark
    I have an array like this: $a = array ( 0 => array ( 'value' => 'America', ), 1 => array ( 'value' => 'England', ), 2 => array ( 'value' => 'Australia', ), 3 => array ( 'value' => 'America', ), 4 => array ( 'value' => 'England', ), 5 => array ( 'value' => 'Canada', ), ) How can I remove the duplicate values so that I get this: $a = array ( 0 => array ( 'value' => 'America', ), 1 => array ( 'value' => 'England', ), 2 => array ( 'value' => 'Australia', ), 4 => array ( 'value' => 'Canada', ), ) I tried using array_unique, but that doesn't work due to this array being multidimensional, I think. Thanks!

    Read the article

  • wsdl return an array of complex types

    - by Anand
    hi, I have defined a web service that will return the data from my mysql data base. I have written the web service in php. Now I have defined a complex type as follows: $server->wsdl->addComplexType( 'Category', 'complexType', 'struct', 'all', '', array( 'category_parent_id' => array('name' => 'category_parent_id', 'type' => 'xsd:int'), 'category_child_id' => array('name' => 'category_child_id', 'type' => 'xsd:int'), 'category_list' => array('name' => 'category_list', 'type' => 'xsd:int') ) ); The above complex type is a row in a table in my database. Now my function must send an array of these rows so how do I achieve the same My code is as follows: require_once('./nusoap/nusoap.php'); $server = new soap_server; $server-configureWSDL('productwsdl', 'urn:productwsdl'); // Register the data structures used by the service $server-wsdl-addComplexType( 'Category', 'complexType', 'struct', 'all', '', array( 'category_parent_id' = array('name' = 'category_parent_id', 'type' = 'xsd:int'), 'category_child_id' = array('name' = 'category_child_id', 'type' = 'xsd:int'), 'category_list' = array('name' = 'category_list', 'type' = 'xsd:int') ) ); $server-register('getaproduct', // method name array(), // input parameters //array('return' = array('result' = 'tns:Category')), // output parameters array('return' = 'tns:Category'), // output parameters 'urn:productwsdl', // namespace 'urn:productwsdl#getaproduct', // soapaction 'rpc', // style 'encoded', // use 'Get the product categories' // documentation ); function getaproduct() { $conn = mysql_connect('localhost','root',''); mysql_select_db('sssl', $conn); $sql = "SELECT * FROM jos_vm_category_xref"; $q = mysql_query($sql); while($r = mysql_fetch_array($q)) { $items[] = array('category_parent_id'=$r['category_parent_id'], 'category_child_id'=$r['category_child_id'], 'category_list'=$r['category_list']); } return $items; } // Use the request to (try to) invoke the service $HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; $server-service($HTTP_RAW_POST_DATA);

    Read the article

  • perl array of array of hashes sorting

    - by srk
    @aoaoh; $aoaoh[0][0]{21} = 31; $aoaoh[0][0]{22} = 31; $aoaoh[0][0]{23} = 17; for $k(0.. $#aoaoh) { for $i(0.. $#aoaoh) { for $val (keys %{$aoaoh[$i][$k]}) { print "$val=$aoaoh[$i][$k]{$val}"; print "\n"; }} } output is 22=31 21=31 23=17 but i expect it to be 21=31 22=31 23=17 Please tell me where is this wrong.. Also how do i sort the values so that i get the output as 23=17 22=31 21=31 (if 2 keys have same value then key with higher value come first)

    Read the article

  • How to send array by post method

    - by GanChinHock.com
    Following is my sample form. <form METHOD="post" METHOD="post" ACTION="index.php" METHOD="post" METHOD="post" METHOD="post"> <input TYPE="text" NAME="array[]" /> <input TYPE="text" NAME="array[]" /> <input TYPE="text" NAME="array[]" /> <input TYPE="text" NAME="array[]" /> <input TYPE="text" NAME="array[]" /> <input TYPE="text" NAME="array[]" /> <input TYPE="text" NAME="array[]" /> <input TYPE="text" NAME="array[]" /> <input TYPE="text" NAME="array[]" /> <input TYPE="text" NAME="array[]" /> <input TYPE="submit" NAME="submit" VALUE="Submit" /> </form> Basically I have 10 inputs of array. Assume my domain is http://domain.com and the file above is index.php. I am trying to fill the form automatically by using the following method. http://domain.com/index.php?array[]=John&array[]=Kelly ... & array[]=Steven Unfortunately, it is not working. :(

    Read the article

  • jquery array: find elements that appear twice in the array

    - by tsiger
    For a markup like this: <div id="set1"> <div id="100">a div</div> <div id="101">another div</div> <div id="102">another div 2</div> <div id="120">same div</div> </div> <div id="set2"> <div id="105">a different div> <div id="101">another div</div> <div id="110">more divs</div> <div id="120">same div</div> </div> As you can see both #set1 and #set2 contain 2 divs with the same id (101, 120). Is it possible somehow with jQuery to find the common elements and add a class to the divs in #set1 that have the same id with divs in #set2? In other words after the script run the above code would look like this: <div id="set1"> <div id="100">a div</div> <div id="101" class="added">another div</div> <div id="102">another div 2</div> <div id="120" class="added">same div</div> </div> <div id="set2"> <div id="105">a different div> <div id="101">another div</div> <div id="110">more divs</div> <div id="120">same div</div> </div>

    Read the article

  • HP p410i array controller - what happens if i add memory?

    - by James
    I have a p410i array controller that only has 256ram. We want to create a raid 5 so we have procured a 512 write back cache module. If we install the write back cache, will this erase the existing raid information. The server currently has 2 disks in raid 1. 6 are spare waiting for an upgrade to create a raid 5. the concern is if we replace/upgrade the memory for the controller, we will wipe the existing production raid 1 array. Thanks in advance.

    Read the article

  • Passing an array of an array of char to a function

    - by L.A. Rabida
    In my program, I may need to load a large file, but not always. So I have defined: char** largefilecontents; string fileName="large.txt"; When I need to load the file, the program calles this function: bool isitok=LoadLargeFile(fileName,largefilecontents); And the function is: bool LoadLargeFile(string &filename, char ** &lines) { if (lines) delete [] lines; ifstream largeFile; #ifdef LINUX largeFile.open(filename.c_str()); #endif #ifdef WINDOWS largeFile.open(filename.c_str(),ios::binary); #endif if (!largeFile.is_open()) return false; lines=new char *[10000]; if (!lines) return false; largeFile.clear(); largeFile.seekg(ios::beg); for (int i=0; i>-1; i++) { string line=""; getline(largeFile,line); if (largeFile.tellg()==-1) break; //when end of file is reached, tellg returns -1 lines[i]=new char[line.length()]; lines[i]=const_cast<char*>(line.c_str()); cout << lines[i] << endl; //debug output } return true; } When I view the debug output of this function, "cout << lines[i] << endl;", it is fine. But when I then check this in the main program like this, it is all messed up: for (i=0; i<10000; i++) cout << largefilecontents[i] << endl; So within the function LoadLargeFile(), the results are fine, but without LoadLargeFile(), the results are all messed up. My guess is that the char ** &lines part of the function isn't right, but I do not know what this should be. Could someone help me? Thank you in advance!

    Read the article

  • Put an array of Objects in nodes of another array of Objects [JAVA]

    - by zengr
    public class hello { public static void main(String[] args) { Object[] newarray = new Object[1]; Object[] obj = new Object[2]; obj[0] = "Number1"; //string value obj[1] = "Number2"; //string value newarray[0] = obj; //this works Object[] tmp_obj = new Object[2]; tmp_obj = newarray[0]; //obviously does not work System.out.println(tmp_obj[0]); //nope System.out.println(tmp_obj[1]); //nope } } So, now if I want to access the values "Number1" and "Number2" which are stored in obj[0] and obj[1]; obj is in newarray[0]. what should I do? Is this a possible? Thanks

    Read the article

  • How to get an array of members of an array

    - by Mystere Man
    Suppose I have a class public class Foo { public Bar { get; set; } } Then I have another class public class Gloop { public List<Foo> Foos { get; set; } } What's the easiest way to get a List of Foo.Bars? I'm using C# 4.0 and can use Linq if that is the best choice. My first thought was something like

    Read the article

  • Fast and efficient way to read a space separated file of numbers into an array?

    - by John_Sheares
    I need a fast and efficient method to read a space separated file with numbers into an array. The files are formatted this way: 4 6 1 2 3 4 5 6 2 5 4 3 21111 101 3 5 6234 1 2 3 4 2 33434 4 5 6 The first row is the dimension of the array [rows columns]. The lines following contain the array data. The data may also be formatted without any newlines like this: 4 6 1 2 3 4 5 6 2 5 4 3 21111 101 3 5 6234 1 2 3 4 2 33434 4 5 6 I can read the first line and initialize an array with the row and column values. Then I need to fill the array with the data values. My first idea was to read the file line by line and use the split function. But the second format listed gives me pause, because the entire array data would be loaded into memory all at once. Some of these files are in the 100 of MBs. The second method would be to read the file in chunks and then parse them piece by piece. Maybe somebody else has a better a way of doing this?

    Read the article

  • Assigning a 2D array (of pointers) to a variable in an object for access in C++?

    - by MrMormon
    I'm sorry if I didn't pick a descriptive or concise name. A lot of questions sound similar, but I haven't been able to find what I'm looking for. What I want to do is store a 2D array of pointers somewhere and assign a variable in some object to that array to be able to access it. Here's some example code that has the same compile error I'm getting with a bigger project. #include <iostream> using namespace std; struct X{ float * b[8][8]; X(){ *(b[1][5]) = 1; cout << *(b[1][5]) << endl; } void Set(float * c[8][8]){ b = c; cout << *(b[1][5]) << endl; } }; main(){ float * a[8][8]; *(a[1][5]) = 2; X obj; obj.Set(a); } What I want to happen in this code is that an X object starts with its own 2D array, whose value pointed to by b[1][5] should be printed as "1". Then the main method's 2D array, a, is passed to the object's Set() method and assigned to its array variable. The value pointed to by b[1][5] should then be printed as "2". However, I can't figure out what type the Set() parameter, c, should be. I get error: incompatible types in assignment of ‘float* (*)[8]’ to ‘float* [8][8]’ when I try to compile. As for why I want to do this, I'm trying to use an array of pointers to objects, not floats, but it's the same error.

    Read the article

  • Delphi: how to set the length of a RTTI-accessed dynamic array using DynArraySetLength?

    - by conciliator
    I'd like to set the length of a dynamic array, as suggested in this post. I have two classes TMyClass and the related TChildClass defined as TChildClass = class private FField1: string; FField2: string; end; TMyClass = class private FField1: TChildClass; FField2: Array of TChildClass; end; The array augmentation is implemented as var RContext: TRttiContext; RType: TRttiType; Val: TValue; // Contains the TMyClass instance RField: TRttiField; // A field in the TMyClass instance RElementType: TRttiType; // The kind of elements in the dyn array DynArr: TRttiDynamicArrayType; Value: TValue; // Holding an instance as referenced by an array element ArrPointer: Pointer; ArrValue: TValue; ArrLength: LongInt; i: integer; begin RContext := TRTTIContext.Create; try RType := RContext.GetType(TMyClass.ClassInfo); Val := RType.GetMethod('Create').Invoke(RType.AsInstance.MetaclassType, []); RField := RType.GetField('FField2'); if (RField.FieldType is TRttiDynamicArrayType) then begin DynArr := (RField.FieldType as TRttiDynamicArrayType); RElementType := DynArr.ElementType; // Set the new length of the array ArrValue := RField.GetValue(Val.AsObject); ArrLength := 3; // Three seems like a nice number ArrPointer := ArrValue.GetReferenceToRawData; DynArraySetLength(ArrPointer, ArrValue.TypeInfo, 1, @ArrLength); { TODO : Fix 'Index out of bounds' } WriteLn(ArrValue.IsArray, ' ', ArrValue.GetArrayLength); if RElementType.IsInstance then begin for i := 0 to ArrLength - 1 do begin Value := RElementType.GetMethod('Create').Invoke(RElementType.AsInstance.MetaclassType, []); ArrValue.SetArrayElement(i, Value); // This is just a test, so let's clean up immediatly Value.Free; end; end; end; ReadLn; Val.AsObject.Free; finally RContext.Free; end; end. Being new to D2010 RTTI, I suspected the error could depend on getting ArrValue from the class instance, but the subsequent WriteLn prints "TRUE", so I've ruled that out. Disappointingly, however, the same WriteLn reports that the size of ArrValue is 0, which is confirmed by the "Index out of bounds"-exception I get when trying to set any of the elements in the array (through ArrValue.SetArrayElement(i, Value);). Do anyone know what I'm doing wrong here? (Or perhaps there is a better way to do this?) TIA!

    Read the article

  • PHP Array Efficiency and Memory Clarification

    - by CogitoErgoSum
    When declaring an Array in PHP, the index's may be created out of order...I.e Array[1] = 1 Array[19] = 2 Array[4] = 3 My question. In creating an array like this, is the length 19 with nulls in between? If I attempted to get Array[3] would it come as undefined or throw an error? Also, how does this affect memory. Would the memory of 3 index's be taken up or 19? Also currently a developer wrote a script with 3 arrays FailedUpdates[] FailedDeletes[] FailedInserts[] Is it more efficient to do it this way, or do it in the case of an associative array controlling several sub arrays "Failures" array(){ ["Updates"] => array(){ [0] => 12 [1] => 41 } ["Deletes"] => array(){ [0] => 122 [1] => 414 [1] => 43 } ["Inserts"] => array(){ [0] => 12 } }

    Read the article

< Previous Page | 33 34 35 36 37 38 39 40 41 42 43 44  | Next Page >