Search Results

Search found 16413 results on 657 pages for 'array manipulation'.

Page 19/657 | < Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >

  • C++ sort array of strings

    - by user69514
    I am trying to sort an array of strings, but it's not sorting anything.... what am I doing wrong? string namesS[MAX_NAMES]; int compare (const void * a, const void * b){ return ( *(char*)a - *(char*)b ); } void sortNames(){ qsort(namesS, MAX_NAMES, sizeof(string), compare); }

    Read the article

  • What's a good matrix manipulation library available for C ?

    - by banister
    Hi, I am doing a lot of image processing in C and I need a good, reasonably lightweight, and above all FAST matrix manipulation library. I am mostly focussing on affine transformations and matrix inversions, so i do not need anything too sophisticated or bloated. Primarily I would like something that is very fast (using SSE perhaps?), with a clean API and (hopefully) prepackaged by many of the unix package management systems. Note this is for C not for C++. Thanks :)

    Read the article

  • Array not showing in Jlist but filled in console

    - by OVERTONE
    Hey there. been a busy debugger today. ill give ths short version. ive made an array list that takes names from a database. then i put the contents of the arraylist into an array of strings. now i want too display the arrays contents in a JList. the weird thing is it was working earlier. and ive two methods. ones just a little practice too make sure i was adding to the Jlist correctly. so heres the key codes. this is the layout of my code. variables constructor methods in my variables i have these 3 defined String[] contactListNames = new String[5]; ArrayList<String> rowNames = new ArrayList<String>(); JList contactList = new JList(contactListNames); simple enough. in my constructor i have them again. contactListNames = new String[5]; contactList = new JList(contactListNames); //i dont have the array list defined though. printSqlDetails(); // the prinSqldetails was too make sure that the connectionw as alright. and its working fine. fillContactList(); // this is the one thats causing me grief. its where all the work happens. // fillContactListTest(); // this was the tester that makes sure its adding to the list alright. heres the code for fillContactListTest() public void fillContactListTest() { for(int i = 0;i<3;i++) { try { String contact; System.out.println(" please fill the list at index "+ i); Scanner in = new Scanner(System.in); contact = in.next(); contactListNames[i] = contact; in.nextLine(); } catch(Exception e) { e.printStackTrace(); } } } heres the main one thats supposed too work. public void fillContactList() { int i =0; createConnection(); ArrayList<String> rowNames = new ArrayList<String>(); try { Statement stmt = conn.createStatement(); ResultSet namesList = stmt.executeQuery("SELECT name FROM Users"); try { while (namesList.next()) { rowNames.add(namesList.getString(1)); contactListNames =(String[])rowNames.toArray(new String[rowNames.size()]); // this used to print out contents of array list // System.out.println("" + rowNames); while(i<contactListNames.length) { System.out.println(" " + contactListNames[i]); i++; } } } catch(SQLException q) { q.printStackTrace(); } conn.commit(); stmt.close(); conn.close(); } catch(SQLException e) { e.printStackTrace(); } } i really need help here. im at my wits end. i just cant see why the first method would add to the JList no problem. but the second one wont. both the contactListNames array and array list can print fine and have the names in them. but i must be transfering them too the jlist wrong. please help p.s im aware this is long. but trust me its the short version.

    Read the article

  • Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a

    - by johnny
    Hi, the following code produces the error in the title. I've tried to google it, but all I got were pages who got the same error (and not an explanation thereof). This isn't really a problem since it's actually working and cancelling the error out with the @ works out just fine. Though I'm still wondering why I haven't been able to execute array_multisort just once without getting this error. public function getMostRelevant(){ list($occurrences, $keywords) = $this->occurr_keyw_array; array_multisort($occurrences, SORT_DESC, SORT_NUMERIC, $keywords); $return_array = array( array($occurrences[0], $keywords[0]), array($occurrences[1], $keywords[1]), array($occurrences[2], $keywords[2]) ); return $return_array; }

    Read the article

  • Submitting a multidimensional array via POST with php

    - by Fireflight
    I have a php form that has a known number of columns (ex. top diameter, bottom diameter, fabric, colour, quantity), but has an unknown number of rows, as users can add rows as they need. I've discovered how to take each of the fields(columns) and place them into an array of their own. <input name="topdiameter['+current+']" type="text" id="topdiameter'+current+'" size="5" /> <input name="bottomdiameter['+current+']" type="text" id="bottomdiameter'+current+'" size="5" /> So what I end up with in the HTML is: <tr> <td><input name="topdiameter[0]" type="text" id="topdiameter0" size="5" /></td> <td><input name="bottomdiameter[0]" type="text" id="bottomdiameter0" size="5" /></td> </tr> <tr> <td><input name="topdiameter[1]" type="text" id="topdiameter0" size="5" /></td> <td><input name="bottomdiameter[1]" type="text" id="bottomdiameter0" size="5" /></td> </tr> ...and so on. What I would like to do now is take all the rows and columns put them into a multidimensional array and email the contents of that to the client (preferably in a nicely formatted table). I haven't been able to really comprehend how to combine all those inputs and selects into a nice array. At this point, I'm going to have to try to use several 1D arrays, although I have the idea that using a single 2D array would be a better practice than using several 1D arrays.

    Read the article

  • append a numpy array to a numpy array

    - by Fraz
    I just started programming in python and am very new to numpy packages.. so still trying to get a hang of it. I have a an numpy_array so something like [ a b c] And then I want to append it into anotehr numpyarray (Just like we create a list of lists) How do we create an array of numpy arrays containing numpy arrays I tried to do the following without any luck >>> M = np.array([]) >>> M array([], dtype=float64) >>> M.append(a,axis=0) Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: 'numpy.ndarray' object has no attribute 'append' >>> a array([1, 2, 3])

    Read the article

  • Array of ArrayList Java

    - by David Bobo
    Hi, I am creating an PriorityQueue with multiple queues. I am using an Array to store the multiple ArrayLists that make up my different PriorityQueues. Here is what I have for my constructor so far: ArrayList<ProcessRecord> pq; ArrayList[] arrayQ; MultiList(){ arrayQ = new ArrayList[9]; pq = new ArrayList<ProcessRecord>(); } The problem comes when I am trying to get the size of the entire array, that is the sum of the sizes of each ArrayList in the array. public int getSize(){ int size = 0; for(int i = 1; i <=9; i++){ size = size + this.arrayQ[i].size(); } return size; } is not seeming to work. Am I declaring the Array of ArrayList correctly? I keep getting an error saying that this.arrayQ[i].size() is not a method. (the .size() being the problem) Thanks for any help! David

    Read the article

  • Numpy: Sorting a multidimensional array by a multidimensional array

    - by JD Long
    Forgive me if this is redundant or super basic. I'm coming to Python/Numpy from R and having a hard time flipping things around in my head. I have a n dimensional array which I want to sort using another n dimensional array of index values. I know I could wrap this in a loop but it seems like there should be a really concise Numpyonic way of beating this into submission. Here's my example code to set up the problem where n=2: a1 = random.standard_normal(size=[2,5]) index = array([[0,1,2,4,3] , [0,1,2,3,4] ]) so now I have a 2 x 5 array of random numbers and a 2 x 5 index. I've read the help for take() about 10 times now but my brain is not groking it, obviously. I thought this might get me there: take(a1, index) array([[ 0.29589188, -0.71279375, -0.18154864, -1.12184984, 0.25698875], [ 0.29589188, -0.71279375, -0.18154864, 0.25698875, -1.12184984]]) but that's clearly reordering only the first element (I presume because of flattening). Any tips on how I get from where I am to a solution that sorts element 0 of a1 by element 0 of the index ... element n?

    Read the article

  • jquery add to an array on click?

    - by KittyYoung
    I'm confused regarding each() and .each()... I think I need to use both, but I'm not sure how... Basically, I have a series of checkboxes and when they're checked, I want to get the id of the closest table row and add it to an array that I can then serialize and pass to a function. So, the html looks like this: <tr id="t1"><td><input type="checkbox" name="did[]" value="232" class="bd" /></td></tr> <tr id="t2"><td><input type="checkbox" name="did[]" value="234" class="bd" /></td></tr> <tr id="t3"><td><input type="checkbox" name="did[]" value="676" class="bd" /></td></tr> <tr><td><button id="tsid" name="tsid" type="button">Send</button></td></tr> And, when (and if) the checkbox is selected, I want to get the closest tr id and store it in an array: var trids = [] And then serialize the input data and the trids array... So far, I only have this: $('#tsid').click(function() { //meant to get the values of the selected checkboxes var myData = $('input[name=did[]]').serialize(); //meant to find and store the closest tr ids in an array... $('.bd').each(function() { var trids = $(this).closest("tr").get(0); //and now I'm lost... }); }

    Read the article

  • AS3: Array of objects parsed from XML remains with zero length

    - by Joel Alejandro
    I'm trying to parse an XML file and create an object array from its data. The data is converted to MediaAlbum classes (class of my own). The XML is parsed correctly and the object is loaded, but when I instantiate it, the Albums array is of zero length, even when the data is loaded correctly. I don't really know what the problem could be... any hints? import Nem.Media.*; var mg:MediaGallery = new MediaGallery("test.xml"); trace(mg.Albums.length); MediaGallery class: package Nem.Media { import flash.net.URLRequest; import flash.net.URLLoader; import flash.events.*; public class MediaGallery { private var jsonGalleryData:Object; public var Albums:Array = new Array(); public function MediaGallery(xmlSource:String) { var loader:URLLoader = new URLLoader(); loader.load(new URLRequest(xmlSource)); loader.addEventListener(Event.COMPLETE, loadGalleries); } public function loadGalleries(e:Event):void { var xmlData:XML = new XML(e.target.data); var album; for each (album in xmlData.albums) { Albums.push(new MediaAlbum(album.attribute("name"), album.photos)); } } } } XML test source: <gallery <albums <album name="Fútbol 9" <photos <photo width="600" height="400" filename="foto1.jpg" / <photo width="600" height="400" filename="foto2.jpg" / <photo width="600" height="400" filename="foto3.jpg" / </photos </album <album name="Fútbol 8" <photos <photo width="600" height="400" filename="foto4.jpg" / <photo width="600" height="400" filename="foto5.jpg" / <photo width="600" height="400" filename="foto6.jpg" / </photos </album </albums </gallery

    Read the article

  • How to print a Perl 2-dimensional array?

    - by Matt Pascoe
    I am trying to write a simple Perl script that reads a *.csv, places the rows of the *.csv file in a two dimensional array, and then prints on item out of the array and then prints a row of the array. #!/usr/bin/perl use strict; use warnings; open(CSV, $ARGV[0]) || die("Cannot open the $ARGV[0] file: $!"); my @row; my @table; while(<CSV>) { @row = split(/\s*,\s*/, $_); push(@table, @row); } close CSV || die $!; foreach my $element ( @{ $table[0] } ) { print $element, "\n"; } print "$table[0][1]\n"; When I run this script I receive the following error and nothing prints: Can't use string ("1") as an ARRAY ref while "strict refs" in use at ./scripts.pl line 16. I have looked in a number of other forums and am still not sure how to fix this issue. Can anyone help me fix this script?

    Read the article

  • How do I set an array in one class with another array in another class

    - by Stef
    I've populated and array with data like this in one class... PowerClass.h NSMutableArray pickerArray; @property (nonatomic, retain) NSMutableArray pickerArray; - PowerClass.m @synthesize pickerArray; @implementation NSMutableArray *array = [[NSArray alloc] initWithObjects:@"stef", @"steve", @"baddamans", @"jonny", nil]; pickerArray = [NSMutableArray arrayWithArray:array]; And I'm trying to set the Array in another class WeekClass.h PowerClass *powerClass; NSMutableArray *pickerData; @property (nonatomic, retain) NSMutableArray pickerData; @property (nonatomic, retain) PowerClass *powerClass; WeekClass.m @implementation pickerData = [NSMutableArray arrayWithArray:powerClass.pickerArray]; I have no errors or warnings. It just crashes. The NSLog says that the powerClass.pickerArray is NULL. Please help point me in the right direction.

    Read the article

  • ArrayAccess multidimensional (un)set?

    - by anomareh
    I have a class implementing ArrayAccess and I'm trying to get it to work with a multidimensional array. exists and get work. set and unset are giving me a problem though. class ArrayTest implements ArrayAccess { private $_arr = array( 'test' => array( 'bar' => 1, 'baz' => 2 ) ); public function offsetExists($name) { return isset($this->_arr[$name]); } public function offsetSet($name, $value) { $this->_arr[$name] = $value; } public function offsetGet($name) { return $this->_arr[$name]; } public function offsetUnset($name) { unset($this->_arr[$name]); } } $arrTest = new ArrayTest(); isset($arrTest['test']['bar']); // Returns TRUE echo $arrTest['test']['baz']; // Echo's 2 unset($arrTest['test']['bar']; // Error $arrTest['test']['bar'] = 5; // Error I know $_arr could just be made public so you could access it directly, but for my implementation it's not desired and is private. The last 2 lines throw an error: Notice: Indirect modification of overloaded element. I know ArrayAccess just generally doesn't work with multidimensional arrays, but is there anyway around this or any somewhat clean implementation that will allow the desired functionality? The best idea I could come up with is using a character as a separator and testing for it in set and unset and acting accordingly. Though this gets really ugly really fast if you're dealing with a variable depth. Does anyone know why exists and get work so as to maybe copy over the functionality? Thanks for any help anyone can offer.

    Read the article

  • Double associative array or indexed + associative array

    - by clover
    I'm undecided what's the best-practice approach for what I'm trying to do. I'm trying to enter data into an array where the data will look like this: apple color: red price: 2 orange color: orange price: 3 banana color: yellow price: 2 pineapple color: yellow price: 5 When I get input, let's say green apple (notice it's a combo of color + name of fruit), I'm going to check if the name of fruit part exists in the array and display its data (if it exists). What's the right way to compose those arrays? How would I do an indexed array containing an associative array? (or would this be better as 2 nested associative arrays, I'm guessing not)

    Read the article

  • Performance question: Inverting an array of pointers in-place vs array of values

    - by Anders
    The background for asking this question is that I am solving a linearized equation system (Ax=b), where A is a matrix (typically of dimension less than 100x100) and x and b are vectors. I am using a direct method, meaning that I first invert A, then find the solution by x=A^(-1)b. This step is repated in an iterative process until convergence. The way I'm doing it now, using a matrix library (MTL4): For every iteration I copy all coeffiecients of A (values) in to the matrix object, then invert. This the easiest and safest option. Using an array of pointers instead: For my particular case, the coefficients of A happen to be updated between each iteration. These coefficients are stored in different variables (some are arrays, some are not). Would there be a potential for performance gain if I set up A as an array containing pointers to these coefficient variables, then inverting A in-place? The nice thing about the last option is that once I have set up the pointers in A before the first iteration, I would not need to copy any values between successive iterations. The values which are pointed to in A would automatically be updated between iterations. So the performance question boils down to this, as I see it: - The matrix inversion process takes roughly the same amount of time, assuming de-referencing of pointers is non-expensive. - The array of pointers does not need the extra memory for matrix A containing values. - The array of pointers option does not have to copy all NxN values of A between each iteration. - The values that are pointed to the array of pointers option are generally NOT ordered in memory. Hopefully, all values lie relatively close in memory, but *A[0][1] is generally not next to *A[0][0] etc. Any comments to this? Will the last remark affect performance negatively, thus weighing up for the positive performance effects?

    Read the article

  • How do I name an array key with a key inside the array

    - by Confused
    I have some data, yes, data. This data came from a MySQL query and it will always contain 4 items, always. I want to cache that data in an array table for use later within a web page but I want to keep the keys from the query and separate out each grouping within a multidimensional array. However to save time iterating through the array each time I want to find a given group of data, I want to call the keys of the first array the same as the ID key which is always the first key within each four items. At the minute I'm using this code: function mysql_fetch_full_result_array($result) { $table_result=array(); $r=0; while($row = mysql_fetch_assoc($result)){ $arr_row=array(); $c=0; while ($c < mysql_num_fields($result)) { $col = mysql_fetch_field($result, $c); $arr_row[$col -> name] = $row[$col -> name]; $c++; } $table_result[$r] = $arr_row; $r++; } return $table_result; } I'm currently testing this using 3 unique users, so I'm getting three rows back from the query and the data from this function ends up in the format: [0]=> . . [id] => 1 . . [name] => random name . . [tel] => random tel . . [post] => post code data [1]=> . . [id] => 34 . . [name] => random name . . [tel] => random tel . . [post] => post code data [2]=> . . [id] => 56 . . [name] => random name . . [tel] => random tel . . [post] => post code data So how do I alter the code to instead of the keys [0], [1], [2] give me the output: [1]=> . . [id] => 1 . . [name] => random name . . [tel] => random tel . . [post] => post code data [34]=> . . [id] => 34 . . [name] => random name . . [tel] => random tel . . [post] => post code data [56]=> . . [id] => 56 . . [name] => random name . . [tel] => random tel . . [post] => post code data I don't mind if the main array keys are strings of numbers rather than numbers but I'm a bit stuck, I tried changing the $table_result[$r] = $arr_row; part to read $table_result[$result['id']] = $arr_row; but that just outputs an array of one person. I know I need another loop but I'm struggling to work out how to write it.

    Read the article

  • Returning the element number of the longest string in an array

    - by JohnRoberts
    I'm trying to get the longestS method to take the user-inputted array of strings, then return the element number of the longest string in that array. I got it to the point where I was able to return the number of chars in the longest string, but I don't believe that will work for what I need. My problem is that I keep getting incompatible type errors when trying to figure this out. I don't understand the whole data type thing with strings yet. It's confusing me how I go about return a number of the array yet the array is of strings. The main method is fine, I got stuck on the ???? part. { public static void main(String [] args) { Scanner inp = new Scanner( System.in ); String [] responseArr= new String[4]; for (int i=0; i<4; i++) { System.out.println("Enter string "+(i+1)); responseArr[i] = inp.nextLine(); } int highest=longestS(responseArr); } public static int longestS(String[] values) { int largest=0 for( int i = 1; i < values.length; i++ ) { if ( ????? ) } return largest; } }

    Read the article

  • Merging multiple array then sorting by array value count

    - by Sofyan
    Hi, Please help me, i need to merge multiple arrays then sorting it by array value count. Below is the problem: $array1 = array("abc", "def", "ghi", "jkl", "mno"); $array2 = array("mno", "jkl", "mno", "ghi", "pqr", "stu"); $array3 = array_merge($array1, $array2); $array4 = ??? print_r($array4); I want the returns of $array4 like this: Array ( [0] => mno [1] => ghi [2] => jkl [3] => abc [4] => def [5] => pqr [6] => stu )

    Read the article

  • array_splice() - Numerical Offsets of Associative Arrays

    - by Alix Axel
    I'm trying to do something but I can't find any solution, I'm also having some trouble putting it into works so here is a sample code, maybe it'll be enough to demonstrate what I'm aiming for: $input = array ( 'who' => 'me', 'what' => 'car', 'more' => 'car', 'when' => 'today', ); Now, I want to use array_splice() to remove (and return) one element from the array: $spliced = key(array_splice($input, 2, 1)); // I'm only interested in the key... The above will remove and return 1 element (third argument) from $input (first argument), at offset 2 (second argument), so $spliced will hold the value more. I'll be iterating over $input with a foreach loop, I know the key to be spliced but the problem is I don't know its numerical offset and since array_splice only accepts integers I don't know what to do. A very dull example: $result = array(); foreach ($input as $key => $value) { if ($key == 'more') { // Remove the index "more" from $input and add it to $result. $result[] = key(array_splice($input, 2 /* How do I know its 2? */, 1)); } } I first though of using array_search() but it's pointless since it'll return the associative index.... How do I determine the numerical offset of a associative index?

    Read the article

  • Only compiles as an array of pointers, not array of arrays

    - by Dustin
    Suppose I define two arrays, each of which have 2 elements (for theoretical purposes): char const *arr1[] = { "i", "j" }; char const *arr2[] = { "m", "n" }; Is there a way to define a multidimensional array that contains these two arrays as elements? I was thinking of something like the following, but my compiler displays warnings about incompatible types: char const *combine[][2] = { arr1, arr2 }; The only way it would compile was to make the compiler treat the arrays as pointers: char const *const *combine[] = { arr1, arr2 }; Is that really the only way to do it or can I preserve the type somehow (in C++, the runtime type information would know it is an array) and treat combine as a multidimensional array? I realise it works because an array name is a const pointer, but I'm just wondering if there is a way to do what I'm asking in standard C/C++ rather than relying on compiler extensions. Perhaps I've gotten a bit too used to Python's lists where I could just throw anything in them...

    Read the article

  • looping through JSON array

    - by Phil Jackson
    Hi all. I have recently posted another question which straight away users pointed me in the right direction. $.ajax({ type: 'POST', url: './', data: 'token=' + token + '&re=8', cache: false, timeout: 5000, success: function(html){ auth(html); var JSON_array = eval(html); alert(JSON_array[0].username); } }); this returns the data correctly but I want to perform a kind of 'foreach'. the array contains data about multiple incoming and outgoing Instant Messages. So if a user is talking to more than one person at a time i need to loop through. the array's structure is as follows. Array ( [0] => Array ( [username] => Emmalene [contents] => <ul><li class="name">ACTwebDesigns</li><li class="speech">helllllllo</li></ul> <ul><li class="name">ACTwebDesigns</li><li class="speech">sds</li></ul> <ul><li class="name">ACTwebDesigns</li><li class="speech">Sponge</li><li class="speech">dick</li></ul> <ul><li class="name">ACTwebDesigns</li><li class="speech">arghh</li></ul> ) ) any help very much appreciated.

    Read the article

  • PHP Array - How to loop through an array

    - by Homer_J
    Hi My array is as follows: Array ( [questions] => q1 [qnum] => 1 [qtext] => I love crisps [page] => 1 ) Array ( [questions] => q2 [qnum] => 2 [qtext] => I love chocolate [page] => 1 ) All I would like to do is print the contents of the array in a loop, so it looks something like: q1 1 I love crisps q2 2 I love chocolate If anyone could supply the PHP and HTML code, that would be great, thanks. Homer.

    Read the article

< Previous Page | 15 16 17 18 19 20 21 22 23 24 25 26  | Next Page >