Search Results

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

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

  • Please help me debug this little C program on dynamic two-dimensional array? [migrated]

    - by azhi
    I am a newbie here. I have written a little C program, which is to create a two-dimensional matrix. Here is the code: #include <stdio.h> #include <stdlib.h> int **CreatMatrix(int m,int n){ int **Matrix; int i; Matrix=(int**)malloc(m*sizeof(int*)); for(i=0;i<m;i++){ Matrix[i]=(int*)malloc(n*sizeof(int)); } return Matrix; } int main(){ int m,n; int **A; printf("Please input the size of the Matrix: "); scanf("%d%d",&m,&n); A=CreatMatrix(m,n); printf("Please input the entries of the Matrix, which should be integers!\n"); int i,j; for(i=0;i<m;i++){ for(j=0;j<n;j++){ scanf("%d",&A[i][j]); } } printf("The Matrix that you input is:\n"); for(i=0;i<m;i++){ for(j=0;j<n;j++){ printf("%3d ",A[i][j]); } printf("\n"); } for(i=0;i<m;i++) free(A[i]); free(A); } I have run it, and it works fine. But I am not sure if it is right? Can anyone help me debug it?

    Read the article

  • How to swap or move 2 string in Array? [on hold]

    - by Wisnu Khazefa
    I have a need to convert .csv file to .dat file. In my problem, there are value pairs, with a name attribute (called Fund) and corresponding numeric value. If the input file has a pair whose value is 0, then that pair (Fund and value) is dropped. The output file should have only those pairs (Fund and value) where the value is non-zero. Here is the prototype of my code. public static void Check_Fund(){ String header = "Text1,Text2,Text3,FUND_UALFND_1,FUND_UALPRC_1,FUND_UALFND_2," +"FUND_UALPRC_2,FUND_UALFND_3,FUND_UALPRC_3,FUND_UALFND_4,FUND_UALPRC_4,FUND_UALFND_5,FUND_UALPRC_5,Text4,Text5,Text6,Text7"; String text = "ABC;CDE;EFG;PRMF;0;PRFF;50;PREF;0;PRCF;0;PRMP;50;TAHU;;BAKWAN;SINGKONG"; String[] head; String[] value; String showText = ""; head = header.split(","); value = text.split(";"); String regex = "\\d+"; String[] fund = {"PREF","PRMF","PRFF","PRCF","PRMP","PDFF","PSEF","PSCB","PSMF","PRGC","PREP"}; for(int i = 0; i < value.length; i++){ for(int j=0;j < fund.length; j++){ if(value[i].equals(fund[j]) && value[i+1].matches(regex)){ if(value[i+1].equals("0")){ value[i] = ""; value[i+1] = ""; } } } showText = showText + head[i] +":" + value[i] + System.lineSeparator(); } System.out.println(showText ); } Expected Result Input: FUND_UALFND_1:PRMF FUND_UALPRC_1:0 FUND_UALFND_2:PRFF FUND_UALPRC_2:50 FUND_UALFND_3:PREF FUND_UALPRC_3:0 FUND_UALFND_4:PRCF FUND_UALPRC_4:0 FUND_UALFND_5:PRMP FUND_UALPRC_5:50 Output: FUND_UALFND_1:PRFF FUND_UALPRC_1:50 FUND_UALFND_2:PRMP FUND_UALPRC_2:50 FUND_UALFND_0: FUND_UALPRC_0: FUND_UALFND_0: FUND_UALPRC_0: FUND_UALFND_0: FUND_UALPRC_0:

    Read the article

  • 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

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