Search Results

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

Page 3/611 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Discrete and Continuous Classifier on Sparse Data

    - by Chris S
    I'm trying to classify an example, which contains discrete and continuous features. Also, the example represents sparse data, so even though the system may have been trained on 100 features, the example may only have 12. What would be the best classifier algorithm to use to accomplish this? I've been looking at Bayes, Maxent, Decision Tree, and KNN, but I'm not sure any fit the bill exactly. The biggest sticking point I've found is that most implementations don't support sparse data sets and both discrete and continuous features. Can anyone recommend an algorithm and implementation (preferably in Python) that fits these criteria? Libraries I've looked at so far include: Orange (Mostly academic. Implementations not terribly efficient or practical.) NLTK (Also academic, although has a good Maxent implementation, but doesn't handle continuous features.) Weka (Still researching this. Seems to support a broad range of algorithms, but has poor documentation, so it's unclear what each implementation supports.)

    Read the article

  • create a sparse BufferedImage in java

    - by elgcom
    I have to create an image with very large resolution, but the image is relatively "sparse", only some areas in the image need to draw. For example with following code /* this take 5GB memory */ final BufferedImage img = new BufferedImage( 36000, 36000, BufferedImage.TYPE_INT_ARGB); /* draw something */ Graphics g = img.getGraphics(); g.drawImage(....); /* output as PNG */ final File out = new File("out.png"); ImageIO.write(img, "png", out); The PNG image on the end I created is ONLY about 200~300 MB. The question is how can I avoid creating a 5GB BufferedImage at the beginning? I do need an image with large dimension, but with very sparse color information. Is there any Stream for BufferedImage so that it will not take so much memory?

    Read the article

  • php transform array into multidim array

    - by fverswijver
    So I'm working on a website with Doctrine as ORM and I get the following array back as a result: Array ( [0] => Array ( [c_cat_id] => 1 [c_title] => Programas e projetos [p_menu] => PBA BR 163 [p_page_id] => 1 ) [1] => Array ( [c_cat_id] => 1 [c_title] => Programas e projetos [p_menu] => Outros projetos [p_page_id] => 3 ) ) Is it possible to transform this array (in PHP) to something like this: Array ( [0] => Array ( [c_cat_id] => 1 [c_title] => Programas e projetos [pages] => Array ([p_page_id] => 1 [p_menu] => PBA BR 163, [p_page_id] => 3 [p_menu] => Outros projetos)) Thanks for your help, always eager to learn new ways of doing things and that's why I love StackOverflow ;)

    Read the article

  • php foreach getting values from an array

    - by sea_1987
    I am having trouble accessing the values in an array, the array looks like this, Array ( [0] => Array ( [id] => 1661 [code] => 849651318 [job_status] => 4 [looking_for] => Lorem ipsum [keywords_education] => Derby University [sector_id_csv] => 10,21,9,22,26 [last_job_title_1] => Programmer [last_job_employer_1] => HBOS [city] => Bury [expected_salary_level] => LEVEL_2 [education_level] => COLLEGE [job_looking_for] => [is_contract] => Y [is_permanent] => N [is_temporary] => Y ) ) Array ( [0] => Array ( [id] => 402 [code] => 849650059 [job_status] => 3 [looking_for] => Lorem ipsum [keywords_education] => Paris College [sector_id_csv] => 27,22,19,21,12 [last_job_title_1] => Programmer [last_job_employer_1] => HSBC [city] => Bury [expected_salary_level] => LEVEL_2 [education_level] => COLLEGE [job_looking_for] => [is_contract] => N [is_permanent] => Y [is_temporary] => Y ) ) Array ( [0] => Array ( [id] => 1653 [code] => 849651310 [job_status] => 3 [looking_for] => Lorem ipsum [keywords_education] => Crewe University [sector_id_csv] => 27,15,19,21,24 [last_job_title_1] => Programmer [last_job_employer_1] => ICI [city] => Bury [expected_salary_level] => LEVEL_2 [education_level] => UNIVERSITY [job_looking_for] => [is_contract] => N [is_permanent] => Y [is_temporary] => Y ) ) I am trying to get the values out, I have tried doing the following, foreach ($result as $rslt) { echo $rslt->id; } I have also tried, foreach ($result as $rslt) { $rslt['id']; } But none of this works, I dont know why, can anyone help?

    Read the article

  • How to check if *number* is in a array

    - by Emil
    Pretty basic programming question, I know PHP have a function for it, but does the iPhone OS have one? I want to check if the current indexPath is a value in an array. PHP Example: <?php $indexPath = 3; $array = array("0", "1", "2", "3", "4"); if (in_array($indexPath, $array)) { // Do something } ?> Does anybody know how to do the same thing inthe iPhone OS?

    Read the article

  • Sparse O(1) array with indices being consecutive products

    - by Kos
    Hello, I'd like to pre-calculate an array of values of some unary function f. I know that I'll only need the values for f(x) where x is of the form of a*b, where both a and b are integers in range 0..N. The obvious time-optimized choice is just to make an array of size N*N and just pre-calculate just the elements which I'm going to read later. For f(a*b), I'd just check and set tab[a*b]. This is the fastest method possible - however, this is going to take a lot of space as there are lots of indices in this array (starting with N+1) which will never by touched. Another solution is to make a simple tree map... but this slows down the lookup itself very heavily by introducing lots of branches. No. I wonder - is there any solution to make such an array less sparse and smaller, but still quick branchless O(1) in lookup?

    Read the article

  • return a php associative array to javascript array

    - by Eric Sim
    I am trying to return a php associative array to javascript array through ajaxRequest.responseText Here's what I do. First in php, I do this: $encoded = json_encode($thisarray); echo $encoded; If I echo $encoded, I get {"a":"apple,arrow","b":"boy,bank","c":"cat,camp"} Then in js script, thisarray = new Array(); thisarray = ajaxRequest.responseText; If I alert thisarray, I get {"a":"apple,arrow","b":"boy,bank","c":"cat,camp"} That's wrong since alerting an array should give error. But in this case, when I alert thisarray, I get the full array!! Needless to say, I can't call my value out of thisarray, since it is yet defined as an array. Anyone can tell me what am I missing here?

    Read the article

  • Copying 1-D array into 2 -D array

    - by Digvijay Yadav
    I have one two dimensional array and one single dimensional array. The two dimensional array is of NxM size. And the one dimensional array is of size N x M means it has N X M elements. Now I want to copy all the elements of the one dimensional array into the 2-D array. This is what I tried for(i = 0; i < M; i += 1) { for(j = 0; j < N; j += 1) { arr2d[i][j] = arr2d[(i*j +j)]; } } But not working Any suggestions???

    Read the article

  • Array sum of difference of first smallest k elment

    - by prateeak ojha
    Hi i come across this challenge on an online programing challange the task is so simple for ex WE have to variable N and K where N is where N is lenght of array and we have to find sum of duiffrence of K smallest element of array as Sample Input 10 4 1 2 3 4 10 20 30 40 100 200 Sample Output 10 Explanation #0 We have 10 as N size of array and K is 4 here the next N values are array's elments in order to find sum of diffrences we will takek smallest values from array which are 1,2,3,4 then will perform operation(sum of difference) as |1-2| + |1-3| + |1-4| + |2-3| + |2-4| + |3-4| = 10 I tried solving the problem and found a way through which i can solve the problem wit N^3 complexity but my solution is rejected i need a approach to solve the problem with n complexity i still can't figure out a way .. looked at some solution but coud'nt find the exact way to approach. if anybody have a better idea and would like to share it would be appreciable thanks in advance

    Read the article

  • loading data from file into 2d array

    - by Chris
    I am just starting with perl and would like some help with arrays please. I am reading lines from a data file and splitting the line into fields: open (INFILE, $infile); do { my $linedata = <INFILE>; my @data= split ',',$linedata; .... } until eof; I then want to store the individual field values (in @data) in and array so that the array looks like the input data file ie, the first "row" of the array contains the first line of data from INFILE etc. Each line of data from the infile contains 4 values, x,y,z and w and once the data are all in the array, I have to pass the array into another program which reads the x,y,z,w and displays the w value on a screen at the point determined by the x,y,z value. I can not pas the data to the other program on a row-by-row basis as the program expects the data to in a 2d matrtix format. Any help greatly appreciated. Chris

    Read the article

  • Sorting an array in ascending order without losing the index Objective-C

    - by thary
    Hello all, I have an array for instance, Array { 3.0 at Index 0 2.0 at Index 1 3.5 at Index 2 1.0 at Index 4 } I would like to get sort it in ascending order without losing the index in the first place, like this, Array { 1.0 at Index 4 2.0 at Index 1 3.0 at Index 0 3.5 at Index 2 } When I sort the array using this, NSArray *sortedArray = [hArray sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; [knnRecog sortUsingDescriptors:[NSArray arrayWithObject:sortAsc]]; I lose the index. Does anyone know a way to preserve the index after sorting the array? Thanks

    Read the article

  • array_merge vs array_value for resetting array index

    - by Jamex
    I have 1 array that I want to re-index. I have found that both array_values and array_merge functions can do the job (and I don't need 2 arrays for the array_merge function to work). Which is faster for a very large array? I would benchmark this, but I don't know how and don't have the large array yet. Before re-index: Array ( [0] => AB [4] => EA [6] => FA [9] => DA [10] => AF ) After re-index: Array ( [0] => AB [1] => EA [2] => FA [3] => DA [4] => AF )

    Read the article

  • Traverse multi dimensional array recusively without using foreach

    - by ejaz
    I have an array like this and the code using foreach loop. $arr = array( array ( array( 'CAR_TIR', 'Tires', 100 ), array( 'CAR_OIL', 'Oil', 10 ), array( 'CAR_SPK', 'Spark Plugs', 4 ) ), array ( array( 'VAN_TIR', 'Tires', 120 ), array( 'VAN_OIL', 'Oil', 12 ), array( 'VAN_SPK', 'Spark Plugs', 5 ) ), array ( array( 'TRK_TIR', 'Tires', 150 ), array( 'TRK_OIL', 'Oil', 15 ), array( 'TRK_SPK', 'Spark Plugs', 6 ) ) ); function recarray($array) { foreach($array as $key=>$value) { if(is_array($value)) { RecArray($value); } else { echo "key = $key value = $value"; } } } recarray($arr); I have to traverse the array using recursion and without using foreach. I would appreciate it if any one can help me

    Read the article

  • Converting 3 dimension byte array to a single byte array [on hold]

    - by Andrew Simpson
    I have a 3 dimensional byte array. The 3-d array represents a jpeg image. Each channel/array represents part of the RGB spectrum. I am not interested in retaining black pixels. A black pixel is represented by this atypical arrangement: myarray[0,0,0] =0; myarray[0,0,1] =0; myarray[0,0,2] =0; So, I have flattened this 3d array out to a 1d array by doing this byte[] AFlatArray = new byte[width x height x 3] and then assigning values respective to the coordinate. But like I said I do not want black pixels. So this array has to only contain color pixels with the x,y coordinate. The result I want is to re-represent the image from the i dimension byte array that only contains non-black pixels. How do I do that? It looks like I have to store black pixels as well because of the xy coordinate system. I have tried writing to a binary file but the size of that file is greater than the jpeg file as the jpeg file is compressed. I am using c#.

    Read the article

  • Convert Array to Multidimensional Array

    - by Tim
    I like to convert a single array into a multidimensional array. This is what I get have web scraping a page, except it is not the end result that I am looking for. Change: Rooms: Array ( [0] => name [1] => value [2] => size [3] => &nbsp; [4] => name [5] => value [6] => size [7] => &nbsp; [8] => name [9] => value [10] => size [11] => &nbsp; [12] => name [13] => value [14] => size [15] => &nbsp; ) Into: Rooms: Array ( Room: Array ( [0] => name [1] => value [2] => size ), Room: Array ( [0] => name [1] => value [2] => size ), Room: Array ( [0] => name [1] => value [2] => size ) )

    Read the article

  • Matching array elements to get an array element at another index

    - by bccarlso
    I have a PHP array that I'm using to generate an HTML form. The PHP array is this: <?php $vdb = array ( array( "Alabama", 275), array( "Alaska", 197), array( "Arizona", 3322)); ?> The PHP to generate the HTML form is below. I need to have the value be the name of the state, because there is some AJAX I'm using to display which states a user has chosen. <?php echo "<table border='1'><thead><tr><th></th><th>State</th><th>Contacts</th><th>Email</th></tr></thead>"; for ($row = 0; $row < 42; $row++) { echo "<tr><td class='input_button'><input type='checkbox' name='vdb[]' value='".$vdb[$row][0]."' title='".$vdb[$row][1]."' /></td>"; echo "<td>".$vdb[$row][0]."</td>"; echo "<td>".$vdb[$row][1]."</td>"; } echo "</table>"; ?> What I'm trying to do is, on submission of the form, with the states the user selected, loop through the PHP array and total the numbers from the selected states. So if I checked Alabama and Alaska, I'd want to add 275 + 197. This is what I thought would have worked, but it's not: <?php $vendors = array(); if (isset($_POST["vdb"])) { $vendors = $_POST["vdb"]; } $ven_i = 0; $ven_j = 0; $ven_total = 0; foreach ($vendors as $value) { foreach ($vdb as $vdb_value) { if ($vendors[$ven_i] == $vdb[$ven_j][0]) { $ven_total += $vdb[$ven_j][1]; } $ven_j++; } $ven_i++; } ?> and then $ven_total should be the total I'm looking for. However, $ven_total just ends up being the first checkbox selected, and it ignores the rest. I am doing this correctly with the AJAX, displaying the total on the front end, but I don't know how to pass that on to the form submission. I'd rather not using GET and URL variables, because a user could type something into the URL and modify the count. Any idea what I'm doing wrong, or a better way to approach this that I would be able to understand? (Very much a novice programmer.)

    Read the article

  • Formula needed: Sort array to array-"snaked"

    - by aw
    After the you guys helped me out so gracefully last time, here is another tricky array sorter for you. I have the following array: a = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16] I use it for some visual stuff and render it like this: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 Now I want to sort the array to have a "snake" later: // rearrange the array according to this schema 1 2 3 4 12 13 14 5 11 16 15 6 10 9 8 7 // the original array should look like this a = [1,2,3,4,12,13,14,5,11,16,15,6,10,9,8,7] Now I'm looking for a smart formula / smart loop to do that ticker = 0; rows = 4; // can be n cols = 4; // can be n originalArray = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]; newArray = []; while(ticker < originalArray.length) { //do the magic here ticker++; } Thanks again for the help.

    Read the article

  • Finding position of each word in a sub-array of a multidimensional array

    - by Shreyas Satish
    I have an array: tokens = [["hello","world"],["hello","ruby"]] all_tokens = tokens.flatten.uniq # all_tokens=["hello","world","ruby"] Now I need to create two arrays corresponding to all_tokens, where the first array will contain the position of each word in sub-array of tokens. I.E Output: [[0,0],[1],[1]] # (w.r.t all_tokens) To make it clear it reads, The index of "hello" is 0 and 0 in the 2 sub-arrays of tokens. And second array contains index of each word w.r.t tokens.I.E Output: [[0,1],[0],[1]] To make it clear it reads,the index of hello 0,1. I.E "hello" is in index 0 and 1 of tokens array. Cheers!

    Read the article

  • Converting array to Drupal format

    - by theo
    Hi all, This statement gives me the value I want in Drupal (namely the last user role): global $user; return (end($user->roles)); however I need to convert it to this format: return array( 0 => array('value' => value for value), // You'll usually want to stop here. Provide more values // if you want your 'default value' to be multi-valued: 1 => array('value' => value for value), 2 => ... ); and I've got no idea how to (also, is this format a multidimensional array?)... Any ideas? Thanks for any help, Theo.

    Read the article

  • Prototype.js: How can i return an array without all the methods Prototypes extends Array with?

    - by Morten
    Hi! Is there a way to return a new version of an array/hash that does not contain all the methods/functions that prototype extends the array object with? Example: var myArray = $A(); myArray['test'] = '1'; myArray['test2'] = '2'; var myVariableToPassToAjax = myArray; If I debug myVariableToPassToAjax it looks like this: Array ( [test] = 1 [test2] = 2 [each] = function each(iterator, context) { .......... .......... } ...and all the other extended array functions ); Is there a way to solve this? :-/ Morten

    Read the article

  • display an array in html table

    - by Davi
    I have this array: Array ( [page] => Array ( [0] => add [1] => edit [2] => delete [3] => search ) [category] => Array ( [0] => add [1] => edit [2] => export ) ) And I want it to be displayed as a html table like this: Page - Category add - add edit - edit delete - export search search I tryed in many ways but didn't work, any solutions? Thank you

    Read the article

  • extract associative array within an array in php

    - by I Like PHP
    i have an array like this Array ( [0] => Array ( [s_id] => 4 [si_id] => sec_1 [d_id] => dep_4 [s_name] => sec1 [s_location] => LA [s_visibility] => yes [s_created_date] => 1273639343 [s_last_updated_date] => 1273639343 [s_created_by] => someone [s_last_updated_by] => everyone ) ) now i want to extract array[0] into an array... means i want this Array ( [s_id] => 4 [si_id] => sec_1 [d_id] => dep_4 [s_name] => sec1 [s_location] => LA [s_visibility] => yes [s_created_date] => 1273639343 [s_last_updated_date] => 1273639343 [s_created_by] => someone [s_last_updated_by] => everyone ) how do i get above results?

    Read the article

  • Populate array from vector

    - by Zag zag..
    Hi, I would like to populate an 2 dimensional array, from a vector. I think the best way to explain myself is to put some examples (with a array of [3,5] length). When vector is: [1, 0] [ [4, 3, 2, 1, 0], [4, 3, 2, 1, 0], [4, 3, 2, 1, 0] ] When vector is: [-1, 0] [ [0, 1, 2, 3, 4], [0, 1, 2, 3, 4], [0, 1, 2, 3, 4] ] When vector is: [-2, 0] [ [0, 0, 1, 1, 2], [0, 0, 1, 1, 2], [0, 0, 1, 1, 2] ] When vector is: [1, 1] [ [2, 2, 2, 1, 0], [1, 1, 1, 1, 0], [0, 0, 0, 0, 0] ] When vector is: [0, 1] [ [2, 2, 2, 2, 2], [1, 1, 1, 1, 1], [0, 0, 0, 0, 0] ] Have you got any ideas, a good library or a plan? Any comments are welcome. Thanks. Note: I consulted Ruby "Matrix" and "Vector" classes, but I don't see any way to use it in my way... Edit: In fact, each value is the number of cells (from the current cell to the last cell) according to the given vector. If we take the example where the vector is [-2, 0], with the value *1* (at array[2, 3]): array = [ [<0>, <0>, <1>, <1>, <2>], [<0>, <0>, <1>, <1>, <2>], [<0>, <0>, <1>, *1*, <2>] ] ... we could think such as: The vector [-2, 0] means that -2 is for cols and 0 is for rows. So if we are in array[2, 3], we can move 1 time on the left (left because 2 is negative) with 2 length (because -2.abs == 2). And we don't move on the top or bottom, because of 0 for rows.

    Read the article

  • perl comparing 2 data file as array 2D for finding match one to one [migrated]

    - by roman serpa
    I'm doing a program that uses combinations of variables ( combiData.txt 63 rows x different number of columns) for analysing a data table ( j1j2_1.csv, 1000filas x 19 columns ) , to choose how many times each combination is repeated in data table and which rows come from (for instance, tableData[row][4]). I have tried to compile it , however I get the following message : Use of uninitialized value $val in numeric eq (==) at rowInData.pl line 34. Use of reference "ARRAY(0x1a2eae4)" as array index at rowInData.pl line 56. Use of reference "ARRAY(0x1a1334c)" as array index at rowInData.pl line 56. Use of uninitialized value in subtraction (-) at rowInData.pl line 56. Modification of non-creatable array value attempted, subscript -1 at rowInData.pl line 56. nothing This is my code: #!/usr/bin/perl use strict; use warnings; my $line_match; my $countTrue; open (FILE1, "<combiData.txt") or die "can't open file text1.txt\n"; my @tableCombi; while(<FILE1>) { my @row = split(' ', $_); push(@tableCombi, \@row); } close FILE1 || die $!; open (FILE2, "<j1j2_1.csv") or die "can't open file text1.txt\n"; my @tableData; while(<FILE2>) { my @row2 = split(/\s*,\s*/, $_); push(@tableData, \@row2); } close FILE2 || die $!; #function transform combiData.txt variable (position ) to the real value that i have to find in the data table. sub trueVal($){ my ($val) = $_[0]; if($val == 7){ return ('nonsynonymous_SNV'); } elsif( $val == 14) { return '1'; } elsif( $val == 15) { return '1';} elsif( $val == 16) { return '1'; } elsif( $val == 17) { return '1'; } elsif( $val == 18) { return '1';} elsif( $val == 19) { return '1';} else { print 'nothing'; } } #function IntToStr ( ) , i'm not sure if it is necessary) that transforms $ to strings , to use the function <eq> in the third loop for the array of combinations compared with the data array . sub IntToStr { return "$_[0]"; } for my $combi (@tableCombi) { $line_match = 0; for my $sheetData (@tableData) { $countTrue=0; for my $cell ( @$combi) { #my $temp =\$tableCombi[$combi][$cell] ; #if ( trueVal($tableCombi[$combi][$cell] ) eq $tableData[$sheetData][ $tableCombi[$combi][$cell] - 1 ] ){ #if ( IntToStr(trueVal($$temp )) eq IntToStr( $tableData[$sheetData][ $$temp-1] ) ){ if ( IntToStr(trueVal($tableCombi[$combi][$cell]) ) eq IntToStr($tableData[$sheetData][ $tableCombi[$combi][$cell] -1]) ){ $countTrue++;} if ($countTrue==@$combi){ $line_match++; #if ($line_match < 50){ print $tableData[$sheetData][4]." "; #} } } } print $line_match." \n"; }

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >