Search Results

Search found 15007 results on 601 pages for 'array'.

Page 11/601 | < Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >

  • Ruby efficient way of building an array from an array of arrays

    - by randombits
    I have an array of ActiveRecord objects, each one which has its own respective errors array. I want to flatten it all out and get only the unique values into one array. So the top level array might look like: foo0 = Foo.new foo1 = Foo.new foo2 = Foo.new foo3 = Foo.new arr = [foo0, foo1, foo2, foo3] Each one of those objects could potentially have an array of errors, and I'd like to get just the unique message out of them and put them in another array, say called error_arr. How would you do it the "Ruby" way?

    Read the article

  • To not iterate through function of Array object if it is added to Array prototype

    - by Rishat Muhametshin
    According to the way to add indexOf method to Array class in IE6, how do I now reject this method from iterating through any random array? For example: Array.prototype.indexOf = function(needle) { ... }; var array = [1, 2, 3]; for (var i in array) { document.write(i + ': ' + array[i]); } gives output 0: 1 1: 2 2: 3 indexOf: function ... How can I skip indexOf property and stop iterating on it without adding any code to where for(...) is called?

    Read the article

  • Powerbuilder Dynamic Array Manipulation

    - by TomatoSandwich
    string array[] long lBound, uBound lBound = LowerBound(array[]) // = 1, empty array value uBound = UpperBound(array[]) // = 0, empty array value array[1] = 'Item 1' array[2] = 'Item 2' array[3] = 'Item 3' lBound = LowerBound(array[]) // = 1 uBound = UpperBound(array[]) // = 3 array[3] = '' //removing item 3 lBound = LowerBound(array[]) // = 1, still uBound = UpperBound(array[]) // = 3, still (but array[3] is nulled? I think the line 'array[3]' is wrong, but I think I've read that this should remove the array cell. What would be the right way to remove an array cell? Does it depend on object type? (String vs Number vs Object) Or Can one manipulate the UpperBound value to make it work? i.e. after removing Item 3, I want the UpperBound, or arraylength, to be 2, since this is logically correct.

    Read the article

  • How to assign the array key a value, when the key name is itself a variable

    - by Matrym
    How do I identify an item in a hash array if the key of the array is only known within a variable? For example: var key = "myKey"; var array = {myKey: 1, anotherKey: 2}; alert(array.key); Also, how would I assign a value to that key, having identified it with the variable? This is, of course, assuming that I must use the variable key to identify which item in the array to alert. Thanks in advance!

    Read the article

  • Accessing 2D array and passing string to label.text

    - by Amir
    Hi. I'm trying to create 2D array and initialize it with NSStrings. When I try to copy content of a cell from the array to a label.text, the application crashes. NSMutableArray *array = [NSMutableArray arrayWithCapacity:0]; [array addObject:[NSMutableArray arrayWithObjects: [NSArray arrayWithObjects: @"0-0", @"0-1", @"0-2", nil], [NSArray arrayWithObjects: @"1-0", @"1-1", @"1-2", nil], [NSArray arrayWithObjects: @"2-0", @"2-1", @"2-2", nil], nil]]; label.text = [[array objectAtIndex:0] objectAtIndex:0]; Any idea why and what am I doing wrong?

    Read the article

  • PHP Sort a multidimensional array by element containing date

    - by user270797
    I have an array such as: Array ( [0] => Array ( [id] => 2 [type] => comment [text] => hey [datetime] => 2010-05-15 11:29:45 ) [1] => Array ( [id] => 3 [type] => status [text] => oi [datetime] => 2010-05-26 15:59:53 ) [2] => Array ( [id] => 4 [type] => status [text] => yeww [datetime] => 2010-05-26 16:04:24 ) ) Can anyone suggest a way to sort/order this based on the datetime element?

    Read the article

  • Adding to a multidimensional array in PHP

    - by b. e. hollenbeck
    I have an array being returned from the database that looks like so: $data = array(201 => array('description' => blah, 'hours' => 0), 222 => array('description' => feh, 'hours' => 0); In the next bit of code, I'm using a foreach and checking the for the key in another table. If the next query returns data, I want to update the 'hours' value in that key's array with a new hours value: foreach ($data as $row => $value){ $query = $db->query($sql); if ($result){ $value['hours'] = $result['hours']; } I've tried just about every combination of declarations for the foreach loop, but I keep getting the error that it's a non-object. Surely this is easier than my brain is perceiving it.

    Read the article

  • slicing 2d numpy array

    - by MedicalMath
    I have a 2d numpy array called FilteredOutput that has 2 columns and 10001 rows, though the number of rows is a variable. I am trying to take the 2nd column of FilteredOutput and use it to populate a new 1d numpy array called timeSeriesArray using the following line of code: timeSeriesArray=p.array(FilteredOutput[:,0]) I got this syntax from the following link. But the problem is that I am getting the following error message: TypeError: list indices must be integers, not tuple Can anyone show me the proper syntax for populating the 1d array timeSeriesArray with the contents of the second column of the 2d array FilteredOutput?

    Read the article

  • PHP sorting an array by mysql date.

    - by daviemanchester
    Hi I have an array that I would like to sort using a date field from a mysql database. Here is a sample of the array which is named 'news' in my class: [48] => Array ( [id] => 14 [type] => 3 [updated] => 2010-04-17 13:54:42 ) [49] => Array ( [id] => 15 [type] => 3 [updated] => 2010-04-17 13:57:21 ) I want to sort de by the 'updated' field. I have some code I have started but am unsure how to complete it and get it working. function sortNews($x) { usort($this->news, array("ProcessClass", "cmp")); //correct sort type? } function cmp($a, $b) { ...................................... missing code } Can anyone help??

    Read the article

  • Android use of an string array on another method

    - by spagi
    Hi all. Im trying to make an activity that has a multiple choice dialog after you push a button. In there you select from a list of things. But these things are received from a web method before the dialog appears. So I create a string array after I receive them inside the onCreate to initialise it there with the correct size. But my dialog method then cant get the array because propably its out of its scope. My code looks like this @Override protected Dialog onCreateDialog(int id) //Here is where the array is loaded to the multiple select dialog etc @Override public void onCreate(Bundle savedInstanceState) //Here is where i initialise the array and get its contents etc I cant initialise my array when the class starts because I dont know its size yet. This has to do something with the scopes of my variables and I am pretty confused

    Read the article

  • C - Discard the edges of an arbitrary level of a multidimensional array

    - by Medivh
    I have some geographical data, that I'm trying to parse into a usable format. The data is kept in NetCDF files, and is read out as a multidimensional array. My problem comes because the source of the geographical data has a strip of longitude on each side of the grid that overlaps the other side. That is, I have a longitude point of -1 degree, and another of 361 degrees. Unfortunately, I've got time, latitude, and sometimes height as dimensions in this array as well, and I have no way of predicting in advance where each dimension will be in the list (or if it's a three dimensional array, or a four dimensional array). Further complicating the problem, the array can be of floats, doubles or integers, so I have to pass it around as a void. Are there any NetCDF tools that I can use to pre-prepare the files? If not, how would you suggest I go about stripping the excess longitudes?

    Read the article

  • A $_GET input paramter that's an Array

    - by donpal
    I'm trying to pass 3 parameter to a script, where the 3rd parameter $_GET['value3'] is supposed to be an array $_GET['value1'] $_GET['value2'] $_GET['value3'] //an array of items I'm calling the script like this: (notice my syntax for value3, I'm not sure it's correct) http://localhost/test.php?value1=test1&value2=test2&value3=[the, array, values] I then use a foreach to hopefully loop through the third parameter value3 which is the array //process the first input $_GET['value1'] //process the second input $_GET['value2'] //process the third input $_GET['value3'] which is the array foreach($_GET['value3'] as $arrayitem){ echo $arrayitem; } but I get the error Invalid argument supplied for foreach() I'm not sure if my methodology is correct. Can some clarify how you'd go about doing the sort of thing

    Read the article

  • Array with mutiple types?

    - by aleluja
    Hello, I was wondering if there is a way to make an array which would have mutiple types of data fields. So far i was using aMyArray: array of array [0..1] of TPoint; But now, it is not enough for me. I need to add 3 more elements to the existing 2 "Point" elements making it an array like aMyArray: array of (TPoint,TPoint,real,real,real) So each element of aMyArray would have 5 'children', 2 of which are of a TPoint type and 3 of them are 'real' type. Is this possible to implement somehow?

    Read the article

  • Array with multiple types?

    - by aleluja
    Hello, I was wondering if there is a way to make an array which would have multiple types of data fields. So far I was using aMyArray: array of array [0..1] of TPoint; But now, it is not enough for me. I need to add 3 more elements to the existing 2 "Point" elements making it an array like aMyArray: array of (TPoint,TPoint,real,real,real) So each element of aMyArray would have 5 'children', 2 of which are of a TPoint type and 3 of them are 'real' type. Is this possible to implement somehow?

    Read the article

  • Perl, `push` to array reference

    - by Mike
    Is it possible to push to an array reference in Perl? Googling has suggested I deference the array first, but this doesn't really work. It pushes to the deferenced array, not the referenced array. For example, my @a = (); my $a_ref = [@a]; push(@$a_ref,"hello"); print $a[0]; @a will not be updated and this code will fail because the array is still empty (I'm still learning Perl references, so this might be an incredibly simple question. Sorry if so)

    Read the article

  • Parsing a complicated array with GetJSON Jquery

    - by Ozaki
    TLDR: Started with this question simplified it after got some of it working and continuing it here. I need to 'GET' the JSON array Format it correctly and for each within the array place it in the corresponding DIV. ?? It works. This is a followup from this question to simplify and continue. I need to some complicated JSON data from an array. With it I need the title and it's value. The reason why I am doing this is because I will know what the array is called but not the data that is being generated inside it. Lets say this new array looks as follows: {"Days": ["Sunday":"10.00", "Monday":"12.00", "Tuesday":"09.00", "Wednesday":"10.00", "Thursday":"02.00", "Friday":"05.00", "Saturday":"08.00"] } I would need it to get Sunday & 10.00 as well as the same for all of the others. My code to parse this at the moment is as follows: $.getJSON(url, function(data){ $.each(data, function(i,item){ $('.testfield').append('<p>' + item + '</p>'); }); }); Without the added times on each date it will parse the data as follows: Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday With the times added to the days in the array Firebug no longer recognizes it as a JSON string. So I am guessing I have formatted something wrong here. Also, I need each day & time to be on a new line I thought that $('.testfield').append('<p>' + item + '</p>' + '<br />'); Would have applied each one to a new line but that did not work. How do I get each day or item to be on a new line? How do I get the $getjson to parse the data correctly day and its value, into a div?

    Read the article

  • Converting a PHP associative array to a JSON associative array

    - by Extrakun
    I am converting a look-up table in PHP which looks like this to JavaScript using json_encode: AbilitiesLookup Object ( [abilities:private] => Array ( [1] => Ability_MeleeAttack Object ( [abilityid:protected] => [range:protected] => 1 [name:protected] => MeleeAttack [ability_identifier:protected] => MeleeAttack [aoe_row:protected] => 1 [aoe_col:protected] => 1 [aoe_shape:protected] => [cooldown:protected] => 0 [focusCost:protected] => 0 [possibleFactions:protected] => 2 [abilityDesc:protected] => Basic Attack ) .....snipped... And in JSON, it is: {"1":{"name":"MeleeAttack","fof":"2","range":"1","aoe":[null,"1","1"],"fp":"0","image":"dummy.jpg"},.... The problem is I get a JS object, not an array, and the identifier is a number. I see 2 ways around this problem - either find a way to access the JSON using a number (which I do not know how) or make it such that json_encode (or some other custom encoding functions) can give a JavaScript associative array. (Yes, I am rather lacking in my JavaScript department). Note: The JSON output doesn't match the array - this is because I do a manual json encoding for each element in the subscript, before pushing it onto an array (with the index as the key), then using json_encode on it. To be clear, the number are not sequential because it's an associative array (which is why the JSON output is not an array).

    Read the article

  • array of structs in C

    - by Hristo
    I'm trying to create an array of structs and also a pointer to that array. I don't know how large the array is going to be, so it should be dynamic. My struct would look something like this: typedef struct _stats_t { int hours[24]; int numPostsInHour; int days[7]; int numPostsInDay; int weeks[20]; int numPostsInWeek; int totNumLinesInPosts; int numPostsAnalyzed; } stats_t; ... and I need to have multiple of these structs for each file (unknown amount) that I will analyze. I'm not sure how to do this. I don't like the following approach because of the limit of the size of the array: # define MAX 10 typedef struct _stats_t { int hours[24]; int numPostsInHour; int days[7]; int numPostsInDay; int weeks[20]; int numPostsInWeek; int totNumLinesInPosts; int numPostsAnalyzed; } stats_t[MAX]; So how would I create this array? Also, would a pointer to this array would look something this? stats_t stats[]; stats_t *statsPtr = &stats[0]; Thanks, Hristo

    Read the article

  • Getting size of a specific byte array from an array of pointers to bytes

    - by Pat James
    In the following example c code, used in an Arduino project, I am looking for the ability to get the size of a specific byte array within an array of pointers to bytes, for example void setup() { Serial.begin(9600); // for debugging byte zero[] = {8, 169, 8, 128, 2,171,145,155,141,177,187,187,2,152,2,8,134,199}; byte one[] = {8, 179, 138, 138, 177 ,2,146, 8, 134, 8, 194,2,1,14,199,7, 145, 8,131, 8,158,8,187,187,191}; byte two[] = {29,7,1,8, 169, 8, 128, 2,171,145,155,141,177,187,187,2,152,2,8,134,199, 2, 2, 8, 179, 138, 138, 177 ,2,146, 8, 134, 8, 194,2,1,14,199,7, 145, 8,131, 8,158,8,187,187,191}; byte* numbers[3] = {zero, one, two }; function(numbers[1], sizeof(numbers[1])/sizeof(byte)); //doesn't work as desired, always passes 2 as the length function(numbers[1], 25); //this works } void loop() { } void function( byte arr[], int len ) { Serial.print("length: "); Serial.println(len); for (int i=0; i<len; i++){ Serial.print("array element "); Serial.print(i); Serial.print(" has value "); Serial.println((int)arr[i]); } } In this code, I understand that sizeof(numbers1)/sizeof(byte)) doesn't work because numbers1 is a pointer and not the byte array value. Is there a way in this example that I can, at runtime, get at the length of a specific (runtime-determined) byte array within an array of pointers to bytes? Understand that I am limited to developing in c (or assembly) for an Arduino environment. Also open to other suggestions rather than the array of pointers to bytes. The overall objective is to organize lists of bytes which can be retrieved, with length, at runtime.

    Read the article

  • How to create extensible dynamic array in Java without using pre-made classes?

    - by AndrejaKo
    Yeah, it's a homework question, so givemetehkodezplsthx! :) Anyway, here's what I need to do: I need to have a class which will have among its attributes array of objects of another class. The proper way to do this in my opinion would be to use something like LinkedList, Vector or similar. Unfortunately, last time I did that, I got fire and brimstone from my professor, because according to his belief I was using advanced stuff without understanding basics. Now next obvious solution would be to create array with fixed number of elements and add checks to get and set which will see if the array is full. If it is full, they'd create new bigger array, copy older array's data to the new array and return the new array to the caller. If it's mostly empty, they'd create new smaller array and move data from old array to new. To me this looks a bit stupid. For my homework, there probably won't be more that 3 elements in an array, but I'd like to make a scalable solution without manually calculating statistics about how often is array filled, what is the average number of new elements added, then using results of calculation to calculate number of elements in new array and so on. By the way, there is no need to remove elements from the middle of the array. Any tips?

    Read the article

  • initialising a 2-dim Array in Scala

    - by Stefan W.
    (Scala 2.7.7:) I don't get used to 2d-Arrays. Arrays are mutable, but how do I specify a 2d-Array which is - let's say of size 3x4. The dimension (2D) is fixed, but the size per dimension shall be initializable. I tried this: class Field (val rows: Int, val cols: Int, sc: java.util.Scanner) { var field = new Array [Char](rows)(cols) for (r <- (1 to rows)) { val line = sc.nextLine () val spl = line.split (" ") field (r) = spl.map (_.charAt (0)) } def put (val rows: Int, val cols: Int, c: Char) = todo () } I get this error: :11: error: value update is not a member of Char field (r) = spl.map (_.charAt (0)) If it would be Java, it would be much more code, but I would know how to do it, so I show what I mean: public class Field { private char[][] field; public Field (int rows, int cols, java.util.Scanner sc) { field = new char [rows][cols]; for (int r = 0; r < rows; ++r) { String line = sc.nextLine (); String[] spl = line.split (" "); for (int c = 0; c < cols; ++c) field [r][c] = spl[c].charAt (0); } } public static void main (String args[]) { new Field (3, 4, new java.util.Scanner ("fraese.fld")); } } and fraese.fld would look, for example, like that: M M M M . M I get some steps wide with val field = new Array Array [Char] but how would I then implement 'put'? Or is there a better way to implement the 2D-Array. Yes, I could use a one-dim-Array, and work with put (y, x, c) = field (y * width + x) = c but I would prefer a notation which looks more 2d-ish.

    Read the article

  • Draw a position from a 2d Array on respected canvas location

    - by Anon
    Background: I have two 2d arrays. Each index within each 2d array represents a tile which is drawn on a square canvas suitable for 8 x 8 tiles. The first 2d array represents the ground tiles and is looped and drawn on the canvas using the following code: //Draw the map from the land 2d array map = new Canvas(mainFrame, 20, 260, 281, 281); for(int i=0; i < world.length; i++){ for(int j=0; j < world[i].length; j++){ for(int x=0; x < 280; x=x+35){ for(int y=0; y < 280; y=y+35){ Point p = new Point(x,y); map.add(new RectangleObject(p,35,35,Colour.green)); } } } } This creates a grid of green tiles 8 x 8 across as intended. The second 2d array represents the position on the ground. This 2d array has everyone of its indexes as null apart from one which is comprised of a Person class. Problem I am unsure of how I can draw the position on the grid. I was thinking of a similar loop, so it draws over the previous 2d array another set of 64 tiles. Only this time they are all transparent but the one tile which isn't null. In other words, the tile where Person is located. I wanted to use a search throughout the loop using a comparative if statement along the lines of if(!(world[] == null)){ map.add(new RectangleObject(p,35,35,Colour.red));} However my knowledge is limited and I am confused on how to implement it.

    Read the article

  • filter by value in object of array

    - by zahir hussain
    hi i want to know how to filter the value in object of array... i just display the below is one data of my object array Object ( [_fields:private] => Array ( [a] => c7b920f57e553df2bb68272f61570210 [index_date] => 2010/05/11 12:00:58 [b] => i am zahir [c] => google.com [d] => 23c4a1f90fb577a006bdef4c718f5cc2 ) ) Object ( [_fields:private] => Array ( [a] => c7b920f57e553df2bb68272f61570210 [index_date] => 2010/05/11 12:00:58 [b] => i am zahir [c] => yahoo.com [d] => 23c4a1f90fb577a006bdef4c718f5cc2 ) ) Object ( [_fields:private] => Array ( [a] => c7b920f57e553df2bb68272f61570210 [index_date] => 2010/05/11 12:00:58 [b] => i am beni [c] => google.com [d] => 23c4a1f90fb577a006bdef4c718f5cc2 ) ) . . . Object ( [_fields:private] => Array ( [a] => c7b920f57e553df2bb68272f61570210 [index_date] => 2010/05/11 12:00:58 [b] => i am sani [c] => yahoo.com [d] => 23c4a1f90fb577a006bdef4c718f5cc2 ) ) i have to filter the [c] value... thanks and advance

    Read the article

  • optimize 2D array in C++

    - by Hristo
    I'm dealing with a 2D array with the following characteristics: const int cols = 500; const int rows = 100; int arr[rows][cols]; I access array arr in the following manner to do some work: for(int k = 0; k < T; ++k) { // for each trainee myscore[k] = 0; for(int i = 0; i < N; ++i) { // for each sample for(int j = 0; j < E[i]; ++j) { // for each expert myscore[k] += delta(i, anotherArray[k][i], arr[j][i]); } } } So I am worried about the array 'arr' and not the other one. I need to make this more cache-friendly and also boost the speed. I was thinking perhaps transposing the array but I wasn't sure how to do that. My implementation turns out to only work for square matrices. How would I make it work for non-square matrices? Also, would mapping the 2D array into a 1D array boost the performance? If so, how would I do that? Finally, any other advice on how else I can optimize this... I've run out of ideas, but I know that arr[j][i] is the place where I need to make changes because I'm accessing columns by columns instead of rows by rows so that is not cache friendly at all. Thanks, Hristo

    Read the article

  • Problem in getting multidimensional array from simple xml object

    - by Rishi2686
    Hi there, As a newbie I need your help in getting multidimensional array from simplexml object. suppose my array is like: just for getting idea: Here $data is a simplexml object contains below xml: <users> <user> <id></id> <nm></nm> <gender> <male></male> <female></female> </gender> </user> </users> Here I an perfectly getting array of each user, but in that array when it comes to gender, it shows nothing. i need array of gender too. I am using following code: foreach($data->users as $users) { $arr1 = array(); foreach($users as $user) { foreach($user as $k=>$v) { $arr1[$k] = (string) $v; } } $arr2[] = $arr1; } Any suggestion?

    Read the article

< Previous Page | 7 8 9 10 11 12 13 14 15 16 17 18  | Next Page >