Search Results

Search found 3545 results on 142 pages for 'arrays'.

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

  • How do i merge the arrays in a particular format?

    - by Pankaj Khurana
    Hi, I have following arrays: 1) for total placed Array ( [0] => Array ( [centers] => Array ( [name] => delhi [id] => 1 ) [0] => Array ( [totalplaced] => 8 ) ) [1] => Array ( [centers] => Array ( [name] => mumbai [id] => 2 ) [0] => Array ( [totalplaced] => 1 ) ) ) 2) for total working Array ( [0] => Array ( [centers] => Array ( [name] => delhi [id] => 1 ) [0] => Array ( [totalworking] => 4 ) ) [1] => Array ( [centers] => Array ( [name] => mumbai [id] => 2 ) [0] => Array ( [totalworking] => 1 ) ) ) 3) for total trained Array ( [0] => Array ( [centers] => Array ( [name] => delhi [id] => 1 ) [0] => Array ( [totaltrained] => 8 ) ) [1] => Array ( [centers] => Array ( [name] => mumbai [id] => 2 ) [0] => Array ( [totaltrained] => 1 ) ) ) I wanted to merge these arrays so that the resultant array should look like this [newarray] => Array( [0] => Array ( [centers] => Array ( [name] => delhi [id] => 1 [totalplaced] => 8 [totalworking] => 4 [totaltrained] => 8 ) ) [1]=> Array( [centers] => Array ( [name] => mumbai [id] => 2 [totalplaced] => 1 [totalworking] => 1 [totaltrained] => 1 ) ) ) This is the tabular representation of the above data which i want to display centername totalplaced totalworking totaltrained delhi 8 4 8 mumbai 1 1 1 Please help me on this. Thanks Pankaj Khurana

    Read the article

  • Arrays of Objects: For each element in array 1, does an object value exist as a value in any of the objects in array 2

    - by DevOtts
    I have two arrays which contain objects in each element of the array. var array1 = [{firstName: "John", lastName: "McDonald"}, {firstName: "Sandy", lastName: "Johnson"},....,] var array2 = [{userName: "Donald"}, {userName: "John"},....,] In psuedo-code, I want to do the following: for each element in array1, is array1[i].firstName == to any of the userName's in array2. In plain english I want to look at each firstname in array1 and see if it exists at all in array2 as the value associated with the userName property.

    Read the article

  • How to tell if 2 arrays share the same element.

    - by Ommit
    So this is a simpler form of my problem. Lets say I have 2 arrays. A= {1,2} and B={2,4,6}. If A and B share an element then delete that element from B. I know you can loop through and compare each element in A to each element in B, but there's got to be a better way!

    Read the article

  • What's the purpose of arrays starting with nonzero index?

    - by helios35
    I tried to find answers, but all I got was answers on how to realize arrays starting with nonzero indexes. Some languages, such as pascal, provide this by default, e.g., you can create an array such as var foobar: array[1..10] of string; I've always been wondering: Why would you want to have the array index not to start with 0? I guess it may be more familiar for beginners to have arrays starting with 1 and the last index being the size of the array, but on a long-term basis, programmers should get used to values starting with 0. Another purpose I could think of: In some cases, the index could actually represent something thats contained in the respective array-entry. e.g., you want to get all capital letters in an array, it may be handy to have an index being the ASCII-Code of the respective letter. But its pretty easy just to subtract a constant value. In this example, you could (in C) simply do something like this do get all capital letters and access the letter with ascii-code 67: #define ASCII_SHIFT 65 main() { int capital_letters[26]; int i; for (i=0; i<26; i++){ capital_letters[i] = i+ASCII_SHIFT; } printf("%c\n", capital_letters[67-ASCII_SHIFT]); } Also, I think you should use hash tables if you want to access entries by some sort of key. Someone might retort: Why should the index always start with 0? Well, it's a hell of a lot simpler this way. You'll be faster when you just have to type one index when declaring an array. Also, you can always be sure that the first entry is array[0] and the last one is array[length_of_array-1]. It is also common that other data structures start with 0. e.g., if you read a binary file, you start with the 0th byte, not the first. Now, why do some programming languages have this "feature" and why do some people ask how to achieve this in languages such as C/C++?, is there any situation where an array starting with a nonzero index is way more useful, or even, something simply cannot be done with an array starting at 0?

    Read the article

  • How to create multiple arrays from 2? (actionscript, flash)

    - by Ole Jak
    so I have array like ParamsArray {a,b,a,a,...b} (so i have 2 kinds of parameters in this array - a and b) (here I have N strings) and another array - DataArray {data1,data2,...dataN} (different strings) (here I have N strings) Now I created 2 new arrays ArrayA and ArrayB and I wanta want to feel arra ArrayA with all data (strings) from DataArray which correspond (by index in array) to a param in ParamsArray. and so strings that correspond to param B should appear in ArrayB. How to do such thing in actionscript? (Please - I need a code example)

    Read the article

  • Why is a fixed size buffers (arrays) must be unsafe?

    - by brickner
    Let's say I want to have a value type of 7 bytes (or 3 or 777). I can define it like that: public struct Buffer71 { public byte b0; public byte b1; public byte b2; public byte b3; public byte b4; public byte b5; public byte b6; } A simpler way to define it is using a fixed buffer public struct Buffer72 { public unsafe fixed byte bs[7]; } Of course the second definition is simpler. The problem lies with the unsafe keyword that must be provided for fixed buffers. I understand that this is implemented using pointers and hence unsafe. My question is why does it have to be unsafe? Why can't C# provide arbitrary constant length arrays and keep them as a value type instead of making it a C# reference type array or unsafe buffers?

    Read the article

  • Typed Arrays in Gecko 2: Float32Array concatenation and expansion.

    - by janesconference
    Hi all, I'm a bit confused with Javascript Typed Arrays. What I have several *Float32Array*s, that have no concat method. I'd like to concatenate them all inside another Float32Array, but: as I said before, there is no concatenation method if I try to write past the array length, the array is not expanded (aka this won't work - please note that event.frameBuffer and buffer are both Float32Array and that I don't know what the final length of my buffer will be): var length_now = buffer.length; for (var i = 0; i < event.frameBuffer.length; i += 1) { buffer [length_now + i] = event.frameBuffer[i]; } The only solution I found is to copy the Float32Array in a regular array, that's definitely not what I want. How would you do, stackoverflowers?

    Read the article

  • Arrays in javascript, how can i learn manipulating it?

    - by Noor
    I've read alot about the core implementation of arrays in javascript and often i find that experimenting is the best way to learn, Right now i have multiple forms where you can type in different things, i want to be able to pull the value of each one and put it in an array so that i can later on read them in in a dynamically created div.. Can anyone point me in the right direction? There is a way i could get around this and that would be by using just one form, and pulling the text from there seperated by comas (,).. the thing is that i don't have the knowledge to pull the text form the form, search and find the comas, then make a new variable i think is neccessary, and read that in.. i know how to "think" javascript, not how to write it.. how do i learn the easiest/fastest way?

    Read the article

  • Why does C++ allow variable length arrays that aren't dynamically allocated?

    - by Maulrus
    I'm relatively new to C++, and from the beginning it's been drilled into me that you can't do something like int x; cin >> x; int array[x]; Instead, you must use dynamic memory. However, I recently discovered that the above will compile (though I get a -pedantic warning saying it's forbidden by ISO C++). I know that it's obviously a bad idea to do it if it's not allowed by the standard, but I previously didn't even know this was possible. My question is, why does g++ allow variable length arrays that aren't dynamically allocated if it's not allowed by the standard? Also, if it's possible for the compiler to do it, why isn't it in the standard?

    Read the article

  • How to merge arrays with same key and different value in PHP?

    - by Martin
    Hi guys, I have arrays similarly to these: 0 => Array ( [0] => Finance / Shopping / Food, [1] => 47 ) 1 => Array ( [0] => Finance / Shopping / Food, [1] => 25 ) 2 => Array ( [0] => Finance / Shopping / Electronic, [1] => 190 ) I need to create one array with [0] as a key and [1] as value. The tricky part is that if the [0] is same it add [1] to existing value. So the result I want is: array ([Finance / Shopping / Food]=> 72, [Finance / Shopping / Electronic] => 190); thanks

    Read the article

  • Using temporary arrays to cut down on code - inefficient?

    - by tommaisey
    I'm new to c++ (and SO) so sorry if this is obvious. I've started using temporary arrays in my code to cut down on repetition and to make it easier to do the same thing to multiple objects. So instead of: MyObject obj1, obj2, obj3, obj4; obj1.doSomming(arg); obj2.doSomming(arg); obj3.doSomming(arg); obj4.doSomming(arg); I'm doing: MyObject obj1, obj2, obj3, obj4; MyObject* objs[] = {&obj1, &obj2, &obj3, &obj4}; for (int i = 0; i !=4; ++i) objs[i]->doSomming(arg); Is this detrimental to performance? Like, does it cause unnecessary memory allocation? Is it good practice? Thanks.

    Read the article

  • Adding multiple byte arrays in c# [migrated]

    - by James P. Wright
    I'm working on a legacy system that uses byte arrays for permission levels. Example: 00 00 00 00 00 00 00 01 means they have "Full Control" 00 00 00 00 00 00 00 02 means they have "Add Control" 00 00 00 00 00 00 00 04 means they have "Delete Control" So, if a User has "00 00 00 00 00 00 00 07" that means they have all 3 (as far as it has been explained to me). Now, my question is that I need to know how to get to "0x07" when creating/checking records. I don't know the syntax for actually combining 0x01, 0x02 and 0x04 so that I come out with 0x07.

    Read the article

  • PowerShell One-Liners: Collections, Hashtables, Arrays and Strings

    The way to learn PowerShell is to browse and nibble, rather than to sit down to a formal five-course meal. In his continuing series on PowerShell one-liners, Michael Sorens provides Fast Food for busy professionals who want results quickly and aren't too faddy. Part 3 has as its tasty confections - Collections, Hashtables, arrays and strings. "A real time saver" Andy Doyle, Head of IT ServicesAndy and his team saved time by automating backup and restores with SQL Backup Pro. Find out how much time you could save. Download a free trial now.

    Read the article

  • arrays format (Javascript)

    - by João Melo
    i have a list of users, with minions, something like this: User52: minion10 minion12 User32: minion13 minion11 i've been keeping in an array where the "location" is the id, like this: Users: [52]User minions: [10]minion [12]minion [32]User minions: [13]minion [11]minion so i can access them easily like this: user[UserID].minions[MinionID] (ex: user[32].minions[11]) but when i print it or send it by json i get something like this: {,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,minion,,,,,,,,,,,,,,minion} but should i keep using like this or should i change to something like this: User = function(){ this.minions = ...; this.getMinion = function(value){ for(var m in this.minions){ if(this.minions[m].id == value){ return this.minions[m]; break; } } } } and get it like this: user.getMinion(MinionID); Question: i get better performance using a "short" array but using loops every time i need a minion, or using "long" arrays, but no need for loop and getting values directly from the id "name"?

    Read the article

  • Why does reusing arrays increase performance so significantly in c#?

    - by Willem
    In my code, I perform a large number of tasks, each requiring a large array of memory to temporarily store data. I have about 500 tasks. At the beginning of each task, I allocate memory for an array : double[] tempDoubleArray = new double[M]; M is a large number depending on the precise task, typically around 2000000. Now, I do some complex calculations to fill the array, and in the end I use the array to determine the result of this task. After that, the tempDoubleArray goes out of scope. Profiling reveals that the calls to construct the arrays are time consuming. So, I decide to try and reuse the array, by making it static and reusing it. It requires some additional juggling to figure out the minimum size of the array, requiring an extra pass through all tasks, but it works. Now, the program is much faster (from 80 sec to 22 sec for execution of all tasks). double[] tempDoubleArray = staticDoubleArray; However, I'm a bit in the dark of why precisely this works so well. Id say that in the original code, when the tempDoubleArray goes out of scope, it can be collected, so allocating a new array should not be that hard right? I ask this because understanding why it works might help me figuring out other ways to achieve the same effect, and because I would like to know in what cases allocation gives performance issues.

    Read the article

  • Good C++ array class for dealing with large arrays of data in a fast and memory efficient way?

    - by Shane MacLaughlin
    Following on from a previous question relating to heap usage restrictions, I'm looking for a good standard C++ class for dealing with big arrays of data in a way that is both memory efficient and speed efficient. I had been allocating the array using a single malloc/HealAlloc but after multiple trys using various calls, keep falling foul of heap fragmentation. So the conclusion I've come to, other than porting to 64 bit, is to use a mechanism that allows me to have a large array spanning multiple smaller memory fragments. I don't want an alloc per element as that is very memory inefficient, so the plan is to write a class that overrides the [] operator and select an appropriate element based on the index. Is there already a decent class out there to do this, or am I better off rolling my own? From my understanding, and some googling, a 32 bit Windows process should theoretically be able address up to 2GB. Now assuming I've 2GB installed, and various other processes and services are hogging about 400MB, how much usable memory do you think my program can reasonably expect to get from the heap? I'm currently using various flavours of Visual C++.

    Read the article

  • Vertex data split into separate buffers or one one structure?

    - by kiba2
    Is it better to have all vertex data in one structure like this: class MyVertex { int x,y,z; int u,v; int normalx, normaly, normalz; } Or to have each component (location, normal, texture coordinates) in separate arrays/buffers? To me it always seemed logical to keep the data grouped together in one structure because they'd always be the same for each instance of a shared vertex and that seems to be true for things like character models (ex: the normal should be an average of adjacent normals for smooth lighting). One instance where this doesn't seem to work is other kinds of meshes like say a cube where the texture coordinates for each may be the same but that causes them to be different where the vertices are shared. Does everybody normally keep them separate? Won't this make them less space efficient if there needs to be an instance of texture coordinates and normals for each triangle vertex (They won't be indexed)? Can OpenGL even handle this mixing of indexed (for location) vs non-indexed buffers in the same VBO?

    Read the article

  • Is there a way to find how how "deep" a PHP array is?

    - by Thomas Owens
    A PHP array can have arrays for its elements. And those arrays can have arrays and so on and so forth. Is there a way to find out the maximum nesting that exists in a PHP array? An example would be a function that returns 1 if the initial array does not have arrays as elements, 2 if at least one element is an array, and so on.

    Read the article

  • Using LINQ to Obtain Max of Columns for Two Dimensional Arrays

    - by Ngu Soon Hui
    Is there anyway to use LINQ to obtain the maximum of each columns for two dimensional arrays? Assume that I have the following: var arrays = new double[5,100](); I want to get the maximum of arrays[0,:], arrays[1,:] .... arrays[4,:]. How to use LINQ to do it? I could have use such method public double GetMax(double[,] arr, int rowIndex) { var colCount = arr.GetLength(1); double max = 0.0; for(int i=0; i<colCount; i++) { max=Math.Max(Math.Abs(arr[rowIndex, i]), max); } return max; } But I would prefer a more succinct ways of doing things.

    Read the article

  • How to create multi-dimensional jagged arrays in VbScript ?

    - by vandana268
    I need to create multi-dimensional array of strings. Each row of the array can have varying number of strings. Something like the follwing code: twoDimension = Array(Array()) ReDim Preserve twoDimension(3) For i = 0 to 2 If i = 1 Then twoDimension(i) = Array(1,2,3) End If If i = 2Then twoDimension(i) = Array(1,2,3,4,5) End If Next

    Read the article

  • Java Array Comparison

    - by BlairHippo
    Working within Java, let's say I have two objects that, thanks to obj.getClass().isArray(), I know are both arrays. Let's further say that I want to compare those two arrays to each other -- possibly by using Arrays.equals. Is there a graceful way to do this without resorting to a big exhaustive if/else tree to figure out which flavor of Arrays.equals needs to be used? I'm looking for something that's less of an eyesore than this: if (obj1 instanceof byte[] && obj2 instanceof byte[]) { return Arrays.equals((byte[])obj1, (byte[])obj2); } else if (obj1 instanceof boolean[] && obj2 instanceof boolean[]) { ...

    Read the article

  • Is there a more efficient AS3 way to compare 2 arrays for adds, removes & updates?

    - by WillyCornbread
    Hi all - I'm wondering if there is a better way to approach this than my current solution... I have a list of items, I then retrieve another list of items. I need to compare the two lists and come up with a list of items that are existing (for update), a list that are not existing in the new list (for removal) and a list of items that are not existing in the old list (for adding). Here is what I'm doing now - basically creating a lookup object for testing if an item exists. Thanks for any tips. for each (itm in _oldItems) { _oldLookup[itm.itemNumber] = itm; } // Loop through items and check if they already exist in the 'old' list for each (itm in _items) { // If an item exists in the old list - push it for update if (_oldLookup[itm.itemNumber]) { _itemsToUpdate.push(itm); } else // otherwise push it into the items to add { _itemsToAdd.push(itm); } // remove it from the lookup list - this will leave only // items for removal remaining in the lookup delete _oldLookup[itm.itemNumber]; } // The items remaining in the lookup object have neither been added or updated - // so they must be for removal - add to list for removal for each (itm in _oldLookup) { _itemsToRemove.push(itm); }

    Read the article

  • How do I sum up weighted arrays in PHP?

    - by christian studer
    Hod do I multiply the values of a multi-dimensional array with weigths and sum up the results into a new array in PHP or in general? The boring way looks like this: $weights = array(0.25, 0.4, 0.2, 0.15); $values = array ( array(5,10,15), array(20,25,30), array(35,40,45), array(50,55,60) ); $result = array(); for($i = 0; $i < count($values[0]); ++$i) { $result[$i] = 0; foreach($weights as $index => $thisWeight) $result[$i] += $thisWeight * $values[$index][$i]; } Is there a more elegant solution?

    Read the article

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