Search Results

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

Page 25/610 | < Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >

  • Convert cell array of cells into cell array of strings in MATLAB

    - by yuk
    Using regexp with tokens on cell array of strings I've got cell array of cells. Here is simplified example: S = {'string 1';'string 2';'string 3'}; res = regexp(S,'(\d)','tokens') res = {1x1 cell} {1x1 cell} {1x1 cell} res{2}{1} ans = '2' I know I have only one match per cell string in S. How I can convert this output into cell arrays of strings in a vectorized form?

    Read the article

  • LINQ - array property contains element from another array

    - by Rob
    I have a object (product), with a property of type 'array' e.g. product.tags = {"tag1","tag2","tag9"} I have an array of input tags to filter on. ... but this is not quite working: List<string> filterTags = new List<string>() { "tag1", "tag3" }; var matches = from p in products where p.Tags.Contains(filterTags) select p; Any recommendations? Thanks.

    Read the article

  • PHP Sum Array - sum only elemants of an array

    - by Homer_J
    Hi all, I have have an array as follows: $row[6] This section of the array has 4 numbers within it that I can display and use without any problems, what I'd like to be able to do is sum the first two numbers and the last two numbers separately. Is there any way to do this? Thanks in advance, Homer.

    Read the article

  • Determining whether one array contains the contents of another array in ruby

    - by Andrew Grimm
    In ruby, how do I test that one array not only has the elements of another array, but contain them in that particular order? correct_combination = [1, 2, 3, 4, 5] [1, 5, 8, 2, 3, 4, 5].function_name(correct_combination) # => false [8, 10, 1, 2, 3, 4, 5, 9].function_name(correct_combination) # => true I tried using include, but that is used to test whether [1,2,3].include?(2) is true or not.

    Read the article

  • JavaScript sorting array from nested array?

    - by Tim
    I have an array: letterFrequency = [["a", 12], ["b", 25], ["c", 34], ["d", 1], ["e", 35], ["f", 8], ["g", 7], ["h", 67], ["i", 35], ["j", 0], ["k", 53], ["l", 0], ["m", 0], ["n", 3], ["o", 0], ["p", 0], ["q", 3], ["r", 153], ["s", 0], ["t", 0], ["u", 15], ["v", 0], ["w", 0], ["x", 3], ["y", 0], ["z", 0]] and I want to sort it in descending order based on the number within the nested array i.e. letterFrequency[i][1]. So I want the most popular letter to be first. How would I do this?

    Read the article

  • combinations of sizes for shipping

    - by Eadz
    Hi there, I've got a bunch of products with sizes to ship and I need to find out the cheapest rate. Given a shipment made out of sizes, say [1,3,3,5] I need to decide how to ship - all together or separate. However it's not as simple as [1,3,3,5] or 1 & 3 & 3 & 5, i need all of the possible combinations something like: [ [[1,3,3,5]], ( 1 shipment ) [[1],[3,3,5]], ( 2 shipments ) [[1,3],[3,5]], ( 2 shipments ) [[1,3,3],[5]], ( 2 shipments ) [[1,5],[3,3]], ( 2 shipments ) [[1,3],[3],[5]], ( 3 shipments ) [[1],[3],[3],[5]] ( 4 shipments ) ] ( etc - many more i assume ) I've tried combinations from the facets gem but it's not quite what i'm after, and I'm not sure how else to approach this problem. I understand it probably has a name and a solution if only I knew the name :) I understand there could be a lot of combinations, but the initial array of sizes won't be larger than 7 or so. Thanks in advance!

    Read the article

  • Converting arrays into another format (PHP)

    - by apis17
    Hi.. i want to convert this array Array ( [2] => Array ( ) [4] => Array ( [12] => Array ( ) [13] => Array ( [16] => Array ( ) ) ) [5] => Array ( ) [10] => Array ( ) [14] => Array ( ) ) into this format Array ( [2] => 2 [4] => Array ( [0] => 12 [13] => Array ( [0] => 16 ) ) [5] => 5 [10] => 10 [14] => 14 ) can anybody help? thanks.

    Read the article

  • storing a sorted array of hashes

    - by srk
    use strict; use warnings; my @aoh =( { 3 => 15, 4 => 8, 5 => 9, }, { 3 => 11, 4 => 25, 5 => 6, }, { 3 => 5, 4 => 18, 5 => 5, }, { 0 => 16, 1 => 11, 2 => 7, }, { 0 => 21, 1 => 13, 2 => 31, }, { 0 => 11, 1 => 14, 2 => 31, }, ); #declaring a new array to store the sorted hashes my @new; print "\n-------------expected output------------\n"; foreach my $href (@aoh) { #i want a new array of hashes where the hashes are sorted my %newhash; my @sorted_keys = sort {$href->{$b} <=> $href->{$a} || $b <=> $a} keys %$href; foreach my $key (@sorted_keys) { print "$key => $href->{$key}\n"; $newhash{$key} = $href->{$key}; } print "\n"; push(@new,\%newhash); } print "-----------output i am getting---------------\n"; foreach my $ref(@new) { my @skeys = sort {$ref->{$a} <=> $ref->{$b} } keys %$ref; foreach my $key (@skeys) { print "$key => $ref->{$key}\n" } print "\n"; } The output of the program : -------------expected output------------ 3 => 15 5 => 9 4 => 8 4 => 25 3 => 11 5 => 6 4 => 18 5 => 5 3 => 5 0 => 16 1 => 11 2 => 7 2 => 31 0 => 21 1 => 13 2 => 31 1 => 14 0 => 11 -----------output i am getting--------------- 4 => 8 5 => 9 3 => 15 5 => 6 3 => 11 4 => 25 3 => 5 5 => 5 4 => 18 2 => 7 1 => 11 0 => 16 1 => 13 0 => 21 2 => 31 0 => 11 1 => 14 2 => 31 Please tell me what am i doing wrong in storing the hashes into a new array.. how do i achieve what i want.. ? Thanks in advance...

    Read the article

  • Multidimensional array with unequal second dimension size using malloc()

    - by user288422
    Hello, I am playing around with multidimensional array of unequal second dimension size. Lets assume that I need the following data structure: [&ptr0]-[0][1][2][3][4][5][6][7][8][9] [&ptr1]-[0][1][2] [&ptr2]-[0][1][2][3][4] int main() { int *a[3]; int *b; int i; a[0] = (int *)malloc(10 * sizeof(int)); a[1] = (int *)malloc(2 * sizeof(int)); a[2] = (int *)malloc(4 * sizeof(int)); for(i=0; i<10; i++) a[0][i]=i; for(i=0; i<2; i++) a[1][i]=i; for(i=0; i<4; i++) a[2][i]=i; } I did some tests and it seems like I can store a value at a[1][3]. Does it mean that rows in my array are of equal size 10?

    Read the article

  • String to array or Array to string tips on formats, etc

    - by user316841
    hi, first of all thanks for taking your time! I'm a junior Dev, working with PHP + mysql. My issue: I'm saving data from a form to my database. From this form, there's only need to save the contacts: Name, phone number, address. But, it would be nice to have a small reference to the user answers. Let's say for each question we've got a value betwee 1 and 4. Since there's no need to create a table just for it, because what's needed is just the personal contacts. I'm thinking of recording each question/answer, as a letter and its correspondent value. Example (A2, B1, C5, D3, etc). My question is: Is there a format I could afterwards, handle easily ? Convert to array (string to array) in case the client change ideas, and ask this data, placed in table columns ? Just to prevent this situation! Example, From (A2, B1, C5 ) to array( "A" = "1", "B" = "1", "C" = "5" ) For now I guess, Regex is the answer, but it's allways hard to figure it out and I'm allways getting in troubles =) Thanks!

    Read the article

  • Generating All Permutations of Character Combinations when # of arrays and length of each array are

    - by Jay
    Hi everyone, I'm not sure how to ask my question in a succinct way, so I'll start with examples and expand from there. I am working with VBA, but I think this problem is non language specific and would only require a bright mind that can provide a pseudo code framework. Thanks in advance for the help! Example: I have 3 Character Arrays Like So: Arr_1 = [X,Y,Z] Arr_2 = [A,B] Arr_3 = [1,2,3,4] I would like to generate ALL possible permutations of the character arrays like so: XA1 XA2 XA3 XA4 XB1 XB2 XB3 XB4 YA1 YA2 . . . ZB3 ZB4 This can be easily solved using 3 while loops or for loops. My question is how do I solve for this if the # of arrays is unknown and the length of each array is unknown? So as an example with 4 character arrays: Arr_1 = [X,Y,Z] Arr_2 = [A,B] Arr_3 = [1,2,3,4] Arr_4 = [a,b] I would need to generate: XA1a XA1b XA2a XA2b XA3a XA3b XA4a XA4b . . . ZB4a ZB4b So the Generalized Example would be: Arr_1 = [...] Arr_2 = [...] Arr_3 = [...] . . . Arr_x = [...] Is there a way to structure a function that will generate an unknown number of loops and loop through the length of each array to generate the permutations? Or maybe there's a better way to think about the problem? Thanks Everyone!

    Read the article

  • Modifying NSMutableDictionary from a single index format into nested (array within array)

    - by Michael Robinson
    I need to take the member ID off the top of this and create an array inside that contains the rest of the JSON return. Here is my JSON return. [{"F_Name_VC":"Frank", "L_Name_VC":"Johnson", "userid":"18", "age":"23", },] After it is json-deserialized it looks like this: I need convert it to be transformed into this, with children sub-array: Someone else posted a similar question but without the fact that it was coming from a JSON deserialization. There were two answers but no conclusion to the question. (Answer 1): NSDictionary *item1 = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@" member",[NSNumber numberWithInt:3],nil] forKeys:[NSArray arrayWithObjects:@"Title",@"View",nil]]; Answer (2): NSMutableArray *Rows = [NSMutableArray arrayWithCapacity: 1]; for (int i = 0; i < 4; ++i) { NSMutableArray *theChildren = [NSMutableArray arrayWithCapacity: 1]; [theChildren addObject: [NSString stringWithFormat: @"tester %d", i]]; NSString *aTitle = [NSString stringWithFormat: @"Item %d", i]; NSDictionary *anItem = [NSDictionary dictionaryWithObjectsAndKeys: aTitle, @"Title", theChildren, @"Children"]; [Rows addObject: anItem]; } NSDictionary *Root = [NSDictionary withObject: Rows andKey: @"Rows"]; Here is my JSON return and save code: NSData *jsonData = [jsonreturn dataUsingEncoding:NSUTF32BigEndianStringEncoding]; NSError *error = nil; NSDictionary * dict = [[CJSONDeserializer deserializer] deserializeAsDictionary:jsonData error:&error]; if (dict) { rowsArray = [dict objectForKey:@"member"]; [rowsArray retain]; } Thanks in advance. Every tutorial on JSON only shows a simple array being returned, never with children..It's driving me crazy trying to figure this out.

    Read the article

  • Uninitialized array offset

    - by kimmothy16
    Hey everyone, I am using PHP to create a form with an array of fields. Basically you can add an unlimited number of 'people' to the form and each person has a first name, last name, and phone number. The form requires that you add a phone number for the first person only. If you leave the phone number field blank on any others, the handler file is supposed to be programmed to use the phone number from the first person. So, my fields are: person[] - a hidden field with a value that is this person's primary key. fname[] - an input field lname[] - an input field phone[] - an input field My form handler looks like this: $people = $_POST['person'] $counter = 0; foreach($people as $person): if($phone[$counter] == '') { // use $phone[0]'s phone number } else { // use $phone[$counter] number } $counter = $counter + 1; endforeach; PHP doesn't like this though, it is throwing me an Notice: Uninitialized string offset error. I debugged it by running the is_array function on people, fname, lname, and phone and it returns true to being an array. I can also manually echo out $phone[2], etc. and get the correct value. I've also ran is_int on the $counter variable and it returned true, so I'm unsure why this isn't working as intended? Any help would be great!

    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

  • 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

  • movieClip in Array displays null, and aren't showing up on stage.addChild(Array[i])

    - by jtdino
    i am new to Actionscript3, i need to know why i keep getting Parameter child must be non-null. And my code won't display 5 enemyBlock objects onto the stage but only just one. any tips and help will be much appreciated. thanks in advance. returns: TypeError: Error #2007: Parameter child must be non-null. at flash.display::DisplayObjectContainer/addChild() at flash.display::Stage/addChild() at BlockDrop_fla::MainTimeline/EnemyBlockPos() at BlockDrop_fla::MainTimeline/frame2() // declare varibles var isEnemyMoving:Boolean = false; var enemyArray:Array; var enemyBlock:MovieClip = new EnemyBlock(); // assign EnemyBlock class to enemyBlock var enemyBlockMC:MovieClip; var count:int = 5; var mapWidth:Number = 800; var mapHeight:Number = 600; function EnemyBlockPos() :void { // assign new MovieClip not null enemyBlockMC = new MovieClip; enemyArray = new Array(); for(var i=1; i<= count; i++){ // add class to MC enemyBlockMC.addChild(enemyBlock); // randomize position enemyBlock.x = Math.round(Math.random()*mapWidth); enemyBlock.y = Math.round(Math.random()*mapHeight); // set motion enemyBlock.movement = 5; // add MC to array enemyArray.push(enemyBlockMC); } for (var w = 1; w <= enemyArray.length; w++) { addChild(enemyArray[w]); } } // endOf EnemyBlockPos

    Read the article

  • Javascript algorithm to find elements in array that are not in another array

    - by Tauren
    I'm looking for a good algorithm to get all the elements in one array that are not elements in another array. So given these arrays: var x = ["a","b","c","t"]; var ?????????y = [???????"d","a","t","e","g"]; I want to end up with this array: var z = ["d","e","g"]; I'm using jquery, so I can take advantage of $.each() and $.inArray(). Here's the solution I've come up with, but it seems like there should be a better way. // goal is to get rid of values in y if they exist in x var x = ["a","b","c","t"]; var y = ["d","a","t","e","g"]; var z = []; $.each(y, function(idx, value){ if ($.inArray(value,x) == -1) { z.push(value); } }); ?alert(z); // should be ["d","e","g"] Here is the code in action. Any ideas?

    Read the article

< Previous Page | 21 22 23 24 25 26 27 28 29 30 31 32  | Next Page >