Search Results

Search found 15239 results on 610 pages for 'array population'.

Page 69/610 | < Previous Page | 65 66 67 68 69 70 71 72 73 74 75 76  | Next Page >

  • Clean solution to this ruby iterator trickiness?

    - by mstksg
    k = [1,2,3,4,5] for n in k puts n if n == 2 k.delete(n) end end puts k.join(",") # Result: # 1 # 2 # 4 # 5 # [1,3,4,5] # Desired: # 1 # 2 # 3 # 4 # 5 # [1,3,4,5] This same effect happens with the other array iterator, k.each: k = [1,2,3,4,5] k.each do |n| puts n if n == 2 k.delete(n) end end puts k.join(",") has the same output. The reason this is happening is pretty clear...Ruby doesn't actually iterate through the objects stored in the array, but rather just turns it into a pretty array index iterator, starting at index 0 and each time increasing the index until it's over. But when you delete an item, it still increments the index, so it doesn't evaluate the same index twice, which I want it to. This might not be what's happening, but it's the best I can think of. Is there a clean way to do this? Is there already a built-in iterator that can do this? Or will I have to dirty it up and do an array index iterator, and not increment when the item is deleted?

    Read the article

  • Pass javascript array to php by using curly braces key name

    - by user7031
    My js code: $(function(){ var arr = new Array('jj', 'kk', 'oo'); $.post('test12.php', {'arr[]': arr}, function(data){ alert(data); }); }); PHP code: <?php echo print_r($_POST['arr']); The thing is,$.post receive a key named 'arr[]',it should be used in PHP as 'arr[]' instead of 'arr',but '$_POST['arr[]']' doesn't work,'arr' works.Which seems that Jquery might do something with curly braces '[]' before sending something to PHP. Secondly,when I remove the single quotas around 'arr[]',PHP can not receive anything by using $_POST['arr'];,I don't know why? Doing this task in a traditional way with no curly braces: $.post('test12.php', {arr: arr}, function(data){ alert(data); }); It works fine. So when sending javascript array to PHP,why bothering using single quote and curly braces like 'arr[]' instead of using a concise way like arr:arr My return result is Array( [0]=>jj [1]=>kk [2]=>oo ) 1 Notice there is a 1 under the array,why?

    Read the article

  • built in Soap extension php5 passing in params as associative array

    - by Ageis
    I have this xml I'm wanting to pass to this web service function <UserName>myuser</UserName> <Password>password</Password> <User> <AddCoverCode /> <title>sdadasdsa</title> </User> </CreateNewUser>','',array(),'document', 'literal'); I'm using the soap extension buit in php5. Is this what I'm supposed to be passing in the soapcall function as parameters? array('CreateNewUser' => array( 'UserName' => 'sc', 'Password' => 'i82372', 'Registration' => array('username' =>'new','password' =>'ss'));

    Read the article

  • Switch two items in associative array PHP

    - by user280381
    Example: $arr = array('apple'='sweet','grapefruit'='bitter','pear'='tasty','banana'='yellow'); I want to switch the positions of grapefruit and pear, so the array will become 'apple'='sweet','pear'='tasty','grapefruit'='bitter','banana'='yellow') I know the keys and values of the elements I want to switch, is there an easy way to do this? Or will it require a loop + creating a new array? Thanks

    Read the article

  • c++: Reference array of maps

    - by donalmg
    I have a function which creates an array of Maps: map<string, int> *pMap And a function which writes maps to the array: int iAddMap(map<string, int> mapToAdd, map<string, int> *m, int i) { m = &(pMap[i]); memcpy(m, mapToAdd, sizeof(map<string, int>)); } And a function to get maps from the array map<string, int>& getMap(int i) { return pMap[i]; } I can write maps to the array without any issue, but every get call results in a seg fault: int val; // val defined after this map<string, int> * pGetMap = &(getMap(val)); Any suggestions on why this is happening?

    Read the article

  • Removing duplicates (within a given tolerance) from a Numpy array of vectors

    - by Brendan
    I have an Nx5 array containing N vectors of form 'id', 'x', 'y', 'z' and 'energy'. I need to remove duplicate points (i.e. where x, y, z all match) within a tolerance of say 0.1. Ideally I could create a function where I pass in the array, columns that need to match and a tolerance on the match. Following this thread on Scipy-user, I can remove duplicates based on a full array using record arrays, but I need to just match part of an array. Moreover this will not match within a certain tolerance. I could laboriously iterate through with a for loop in Python but is there a better Numponic way?

    Read the article

  • c++ multithread array

    - by user1731972
    i'm doing something for fun, trying to learn multithreading Problems passing array by reference to threads but Arno pointed out that my threading via process.h wasn't going to be multi-threaded. What I'm hoping to do is something where I have an array of 100 (or 10,000, doesn't really matter I don't think), and split up the assignment of values to each thread. Example, 4 threads = 250 values per thread to be assigned. Then I can use this filled array for further calculations. Here's some code I was working on (which doesn't work) #include <process.h> #include <windows.h> #include <iostream> #include <fstream> #include <time.h> //#include <thread> using namespace std; void myThread (void *dummy ); CRITICAL_SECTION cs1,cs2; // global int main() { ofstream myfile; myfile.open ("coinToss.csv"); int rNum; long numRuns; long count = 0; int divisor = 1; float holder = 0; int counter = 0; float percent = 0.0; HANDLE hThread[1000]; int array[10000]; srand ( time(NULL) ); printf ("Runs (use multiple of 10)? "); cin >> numRuns; for (int i = 0; i < numRuns; i++) { //_beginthread( myThread, 0, (void *) (array1) ); //??? //hThread[i * 2] = _beginthread( myThread, 0, (void *) (array1) ); hThread[i*2] = _beginthread( myThread, 0, (void *) (array) ); } //WaitForMultipleObjects(numRuns * 2, hThread, TRUE, INFINITE); WaitForMultipleObjects(numRuns, hThread, TRUE, INFINITE); } void myThread (void *param ) { //thanks goes to stockoverflow //http://stackoverflow.com/questions/12801862/problems-passing-array-by-reference-to-threads int *i = (int *)param; for (int x = 0; x < 1000000; x++) { //param[x] = rand() % 2 + 1; i[x] = rand() % 2 + 1; } } Can anyone explain why it isn't working?

    Read the article

  • Two dimensional array search in objective c

    - by Filthy Night
    Hi All, i want to ask question that how can we search in a plist which is of array type and has elements of array type as well. i am searching from a plist which is of string element type and its working fine, but i am not able to search when it has array elements in the plist. Regards!

    Read the article

  • Creating a New Reverse Java Array

    - by mandir08
    Given an array of ints length 3, return a new array with the elements in reverse order, so {1, 2, 3} becomes {3, 2, 1}. public int[] reverse3(int[] nums) { int[] values = new int[3]; for(int i=0; i<=nums.length-1; i++) { for(int j=nums.length-1; j>=0; j--) { values[i]=nums[j]; } } return values; } I cant get this to work properly, usually the last int in the array, becomes every single int in the new array

    Read the article

  • encode array to JSON in PHP to get [elm1,elm2,elm3] instead of {elm1:{},elm2:{},elm3:{}}

    - by Itay Moav
    I am trying to json_encode an array, which is what returns from a Zend_DB query. var_dump gives: (Manually adding 0 member does not change the picture). array(3) { [1]=> array(3) { ["comment_id"]=> string(1) "1" ["erasable"]=> string(1) "1" ["comment"]=> string(6) "test 1" } [2]=> array(3) { ["comment_id"]=> string(1) "2" ["erasable"]=> string(1) "1" ["comment"]=> string(6) "test 1" } [3]=> array(3) { ["comment_id"]=> string(1) "3" ["erasable"]=> string(1) "1" ["comment"]=> string(6) "jhghjg" } } The encoded string looks: {"1":{"comment_id":"1","erasable":"1","comment":"test 1"}, "2":{"comment_id":"2","erasable":"1","comment":"test 1"}, "3":{"comment_id":"3","erasable":"1","comment":"jhghjg"}} While I need it as: [{"comment_id":"1","erasable":"1","comment":"test 1"}, {"comment_id":"2","erasable":"1","comment":"test 1"}, {"comment_id":"3","erasable":"1","comment":"jhghjg"}] As the php.ini/json__encode documentation says it should. Any ideas?

    Read the article

  • Passing an array argument from C# to a C++/CLI method

    - by jco
    I know only very little about C++/CLI, but I have a simple problem that needs a solution. I have a C++/CLI class method that takes a byte-array as a parameter. The array is of a pre-determined length, and can be allocated in C# beforehand. The array is supposed to be filled with data by the C++/CLI method. How do I declare the method and then call it from C#? I tried something like having the following in my C++/CLI class: public ref class C { public: void FillBytes(array<BYTE^>^ bytes); }; And then, in C#: o = new C(); var bytes = new byte[3]; o.FillBytes(bytes); But that didn't work at all :).

    Read the article

  • Taking wrong database configuration array

    - by user309076
    Hi, I have one application in which i have used 2 database connections. In my database config file i have given two arrays as below. $active_group = ‘default’; $active_record = TRUE; FIRST ARRAY $db[‘default’][‘hostname’] = ‘hostname’; .............. .......... SECOND ARRAY $db[‘another_db’][‘hostname’] = ‘hostname’; .............. .......... this is working fine. Now, I copied the entire CI folder to develop another application in which only one database connection needed. So, now, in the database config file, i deleted the second configuration array. But, the db class is taking first application’s second array i.e. “another_db” and it is giving the below error. “You have specified an invalid database connection group.” When i change the default (only one) array name to “another_db” in configuration file. It is working fine. Can’t understand from where it is taking the group name as “another_db”. My application autoloads database library. I have debugged the ci_auto_loader in Loader.php class where it calls $this-database() function with no parameters. But in function database($params, $, $) {}, if I echo $params it shows “another_db”.

    Read the article

  • php: how do i store an array in a file to access as an array later with php?

    - by Haroldo
    I just want to quickly store an array which i get from a remote API, so that i can mess around with it on a local host. So: i currently have an array i want to people to use the array without having to get it from the API There are no needs for efficiency etc here, this isnt for an actual site just for getting some sanitizing/formatting methods made etc is there a function like store_array() restore_arrray() ?!

    Read the article

  • Decayed multidimensional array return from function

    - by paul simmons
    related to http://stackoverflow.com/questions/2520535/gcc-multi-dim-array-or-double-pointer-for-warning-free-compile , is there a way to return so-called "decayed array pointer" from a function? in summary (suppose 2 dim array) returning int (*a)[5] format rather than int** format? as far as I see, when returned int** pointer is sent to another function waiting (int*)[] parameter, it is not working correctly.

    Read the article

  • Replace duplicate values in array with new randomly generated values

    - by RussellDias
    I have below a function (created by Gordon in a previous question that went unanswered) that creates an array with n amount of values. The sum of the array is equal to $max. function randomDistinctPartition($n, $max) { $partition= array(); for($i=1; $i < $n; $i++) { $maxSingleNumber = $max - $n; $partition[] = $number = rand(1, $maxSingleNumber); } $max -= $number; } $partition[] = $max; return $partition; } For example: If I set $n = 4 and $max = 30. Then I should get the following. array(5, 7, 10, 8); However, this function does not take into account duplicates and 0s. What I would like - and have been trying to accomplish - is to generate an array with unique numbers that add up to my predetermined variable $max. No Duplicate numbers and No 0 and/or negative integers.

    Read the article

  • Serialize boost array

    - by jules
    I would like to serialize a boost::array, containing something that is already serializable. If get this error: error C2039: 'serialize' : is not a member of 'boost::array<T,N>' I have tried to include the serialization/array.hpp header but it did not help. Is there another header to include ? According to the documentation I should be able to do that http://www.chuchusoft.com/serialization/doc/boost_types.html Thanks

    Read the article

  • Get Array value by string of keys

    - by Esben Petersen
    Hello, i'm building a template engine for my next project, which is going great. It replaces {tag} with a corresponding value. But, i want {tag[0][key]} to be replaced as well. All i need to know is how to get the value, if i have the string representation of the array and key, like this: $arr = array( 0=>array( 'key'=>'value' ), 1=>array( 'key'=>'value2' ) ); $tag = 'arr[0][key]'; echo($$tag); This is a very simple version of the problem, i hope you understand it. Or else i would be happy to anwser any questions about it :) Thanks for any help in advantage

    Read the article

  • Sending array through email on iphone

    - by thary
    Hey guys I need to send the content of an NSMutableArray through email. I have a mailing function but I'm not sure on how to place the content of the array into a NSString to be displayed on the email under each other. Is there a way to place all the content of the array into the string with maybe HTML nextline command between each array element? NSString *emailBody = @"Need to put the body here"; Thanks

    Read the article

  • An array of MySQL results...

    - by Michael Falk
    What am I doing wrong here? I am attempting to return a json object and I can't seem to get past the array... I've built hundreds of regular array and returned them as a json object but I am having a hard time wrapping my head around this one. $rows = array(); $post_array = array(); $i = 0; $result = mysql_query(" SELECT * FROM forum_posts WHERE permalink = '$permalink' AND LOWER(raw_text) LIKE '%$str%' " ); while($row = mysql_fetch_assoc($result)) { $post_array[$i] = $rows[ "id" => htmlentities($row["id"]), "post_content" => htmlentities($row["content"]), "author" => $row["author"], "last_updated" => $row["last_updated"], "author_id" => $row["author_id"], "editing_author" => $row["editing_author"], "date" => $outputQuoteDate ]; $i++; }

    Read the article

  • Using array of Action() in a lambda expression

    - by Sean87
    I want to do some performance measurement for a method that does some work with int arrays, so I wrote the following class: public class TimeKeeper { public TimeSpan Measure(Action[] actions) { var watch = new Stopwatch(); watch.Start(); foreach (var action in actions) { action(); } return watch.Elapsed; } } But I can not call the Measure mehotd for the example below: var elpased = new TimeKeeper(); elpased.Measure( () => new Action[] { FillArray(ref a, "a", 10000), FillArray(ref a, "a", 10000), FillArray(ref a, "a", 10000) }); I get the following errors: Cannot convert lambda expression to type 'System.Action[]' because it is not a delegate type Cannot implicitly convert type 'void' to 'System.Action' Cannot implicitly convert type 'void' to 'System.Action' Cannot implicitly convert type 'void' to 'System.Action' Here is the method that works with arrays: private void FillArray(ref int[] array, string name, int count) { array = new int[count]; for (int i = 0; i < array.Length; i++) { array[i] = i; } Console.WriteLine("Array {0} is now filled up with {1} values", name, count); } What I am doing wrong?

    Read the article

  • iPhone: Get value in multi-dimentional array

    - by Nic Hubbard
    I have an array that is many levels deep and I am wondering what is the best way to get one of the child element values that is deep in my array. I assume I need to use a recursive method, but what is the best way to do this? Or is there a faster way to do this? The array comes from an XML Parser that I am using which builds everything into an array like this (using NSLog to show the structure): { children = ( { children = ( { children = ( { children = ( ); data = 12; element = AssetID; } ); data = ""; element = "ns1:GetUserIdByUsernameResponse"; } ); data = ""; element = "SOAP-ENV:Body"; } ); data = ""; element = "SOAP-ENV:Envelope"; } What I would like to get at is the AssetID data, which in this case is 12.

    Read the article

  • Getting An Array Result From A C# Method

    - by Soo
    I am trying to write some code to return an array in C#, but don't know the proper syntax. I think my method is set up correctly, but to set an array to the result of the method is what I'm having difficulty with. Method Declaration: double[,] function(double variable) { ... code ... return array }

    Read the article

  • Reading in data from a file into an array

    - by Sam
    If I have an options file along the lines of this: size = 4 data = 1100010100110010 And I have a 2d size * size array that I want to populate the values in data into, what's the best way of doing it? To clarify, for the example I have I'd want an array like this: int[4][4] array = {{1,1,0,0}, {0,1,0,1}, {0,0,1,1}, {0,0,1,0}}. (Not real code but you get the idea). Size can be really be any number though. I'm thinking I'd have to read in the size, maloc an array and then maybe read in a string full of data then loop through each char in the data, cast it to an int and stick it in the appropriate index? But I really have no idea how to go about it, have been searching for a while with no luck. Any help would be cool! :)

    Read the article

< Previous Page | 65 66 67 68 69 70 71 72 73 74 75 76  | Next Page >