Search Results

Search found 3545 results on 142 pages for 'arrays'.

Page 17/142 | < Previous Page | 13 14 15 16 17 18 19 20 21 22 23 24  | Next Page >

  • linear combinations in python/numpy

    - by nmaxwell
    greetings, I'm not sure if this is a dumb question or not. Lets say I have 3 numpy arrays, A1,A2,A3, and 3 floats, c1,c2,c3 and I'd like to evaluate B = A1*c1+ A2*c2+ A3*c3 will numpy compute this as for example, E1 = A1*c1 E2 = A2*c2 E3 = A3*c3 D1 = E1+E2 B = D1+E3 or is it more clever than that? In c++ I had a neat way to abstract this kind of operation. I defined series of general 'LC' template functions, LC for linear combination like: template<class T,class D> void LC( T & R, T & L0,D C0, T & L1,D C1, T & L2,D C2) { R = L0*C0 +L1*C1 +L2*C2; } and then specialized this for various types, so for instance, for an array the code looked like for (int i=0; i<L0.length; i++) R.array[i] = L0.array[i]*C0 + L1.array[i]*C1 + L2.array[i]*C2; thus avoiding having to create new intermediate arrays. This may look messy but it worked really well. I could do something similar in python, but I'm not sure if its nescesary. Thanks in advance for any insight. -nick

    Read the article

  • For each result in MySQL query, push to array (complicated)

    - by Dylan Taylor
    Okay, here's what I'm trying to do. I am running a MySQL query for the most recent posts. For each of the returned rows, I need to push the ID of the row to an array, then within that ID in the array, I need to add more data from the rows. A multi-dimensional array. Here's my code thus far. $query = "SELECT * FROM posts ORDER BY id DESC LIMIT 10"; $result = mysql_query($query); while($row = mysql_fetch_array($result)){ $id = $row["id"]; $post_title = $row["title"]; $post_text = $row["text"]; $post_tags = $row["tags"]; $post_category = $row["category"]; $post_date = $row["date"]; } As you can see I haven't done anything with arrays yet. Here's an ideal structure I'm looking for, just incase you're confused. The master array I guess you could call it. We'll just call this array $posts. Within this array, I have one array for each row returned in my MySQL query. Within those arrays there is the $post_title, $post_text, etc. How do I do this? I'm so confused.. an example would be really appreciated. -Dylan

    Read the article

  • What collection object is appropriate for fixed ordering of values?

    - by makerofthings7
    Scenario: I am tracking several performance counters and have a CounterDescription[] correlate to DataSnapshot[]... where CounterDescription[n] describes the data loaded within DataSnapshot[n]. I want to expose an easy to use API within C# that will allow for the easy and efficient expansion of the arrays. For example CounterDescription[0] = Humidity; DataSnapshot[0] = .9; CounterDescription[1] = Temp; DataSnapshot[1] = 63; My upload object is defined like this: Note how my intent is to correlate many Datasnapshots with a dattime reference, and using the offset of the data to refer to its meaning. This was determined to be the most efficient way to store the data on the back-end, and has now reflected itself into the following structure: public class myDataObject { [DataMember] public SortedDictionary<DateTime, float[]> Pages { get; set; } /// <summary> /// An array that identifies what each position in the array is supposed to be /// </summary> [DataMember] public CounterDescription[] Counters { get; set; } } I will need to expand each of these arrays (float[] and CounterDescription[] ), but whatever data already exists must stay in that relative offset. Which .NET objects support this? I think Array[] , LinkedList<t>, and List<t> Are able to keep the data fixed in the right locations. What do you think?

    Read the article

  • Infile incomplete type error

    - by kd7vdb
    I am building a program that takes a input file in this format: title author title author etc and outputs to screen title (author) title (author) etc The Problem I am currently getting is a error "ifstream infile has incomplee type and cannot be defined" #include <iostream> #include <string> #include <ifstream> using namespace std; string bookTitle [14]; string bookAuthor [14]; int loadData (string pathname); void showall (int counter); int main () { int counter; string pathname; cout<<"Input the name of the file to be accessed: "; cin>>pathname; loadData (pathname); showall (counter); } int loadData (string pathname) // Loads data from infile into arrays { ifstream infile; int counter = 0; infile.open(pathname); //Opens file from user input in main if( infile.fail() ) { cout << "File failed to open"; return 0; } while (!infile.eof()) { infile >> bookTitle [14]; //takes input and puts into parallel arrays infile >> bookAuthor [14]; counter++; } infile.close; } void showall (int counter) // shows input in title(author) format { cout<<bookTitle<<"("<<bookAuthor<<")"; } Thanks ahead of time, kd7vdb

    Read the article

  • How to process a large post array in PHP where item names are all different and not known in advance

    - by Salnajjar
    I have a PHP page that queries a DB to populate a form for the user to modify the data and submit. The query returns a number of rows which contain 3 items: ImageID ImageName ImageDescription The PHP page titles each box in the form with a generic name and appends the ImageID to it. Ie: ImageID_03 ImageName_34 ImageDescription_22 As it's unknown which images are going to have been retrieved from the DB then I can't know in advance what the name of the form entries will be. The form deals with a large number of entries at the same time. My backend PHP form processor that gets the data just sees it as one big array: [imageid_2] => 2 [imagename_2] => _MG_0214 [imageid_10] => 10 [imagename_10] => _MG_0419 [imageid_39] => 39 [imagename_39] => _MG_0420 [imageid_22] => 22 [imagename_22] => Curly Fern [imagedescription_2] => Wibble [imagedescription_10] => Wobble [imagedescription_39] => Fred [imagedescription_22] => Sally I've tried to do an array walk on it to split it into 3 arrays which set places but am stuck: // define empty arrays $imageidarray = array(); $imagenamearray = array(); $imagedescriptionarray = array(); // our function to call when we walk through the posted items array function assignvars($entry, $key) { if (preg_match("/imageid/i", $key)) { array_push($imageidarray, $entry); } elseif (preg_match("/imagename/i", $key)) { // echo " ImageName: $entry"; } elseif (preg_match("/imagedescription/i", $key)) { // echo " ImageDescription: $entry"; } } array_walk($_POST, 'assignvars'); This fails with the error: array_push(): First argument should be an array in... Am I approaching this wrong?

    Read the article

  • php Getting the 'new' values in an array

    - by Mark
    Trying to learn about php's arrays today. I have a set of arrays like this: $a = array ( 0 => array ( 'value' => 'America', ), 1 => array ( 'value' => 'England', ), 2 => array ( 'value' => 'Australia', ), ) $b = array ( 0 => array ( 'value' => 'America', ), 1 => array ( 'value' => 'England', ), 2 => array ( 'value' => 'Canada', ), ) I need to get the 'new' subarrays that array b brings to the table. ie, I need to return array ( 'value' => 'Canada', ) I thought I could first merge $a+$b and then compare the result to $a. $merge = array_merge($a,$b); $result = array_diff($merge,$a); But somehow that does not work. It returns array() How come? And thanks!

    Read the article

  • Drupal PHP error zval can't be arrays

    - by Steven
    Guys and Gals, Im getting this error Internal zval's can't be arrays, objects or resources in Unknown on line 0 on a site that was built in drupal, it appears to be crashing httpd.exe Faulting application httpd.exe, version 2.2.14.0, time stamp 0x4aeb9704, faulting module php5ts.dll, version 5.3.1.0, time stamp 0x4b06c41d, exception code 0xc0000005, fault offset 0x000c31b6, process id 0x1410, application start time 0x01cb031455273060. I never built the site and have never touched drupal or php. Can anyone shed light on what might be happening? Thanks Sp

    Read the article

  • Optimizing mathematics on arrays of floats in Ada 95 with GNAT

    - by mat_geek
    Consider the bellow code. This code is supposed to be processing data at a fixed rate, in one second batches, It is part of an overal system and can't take up too much time. When running over 100 lots of 1 seconds worth of data the program takes 35 seconds (or 35%), executing this function in a loop. The test loop is timed specifically with Ada.RealTime. The data is pregenerated so the majority of the execution time is definatetly in this loop. How do I improce the code to get the processing time down to a minimum? The code will be running on an Intel Pentium-M which is a P3 with SSE2. package FF is new Ada.Numerics.Generic_Elementary_Functions(Float); N : constant Integer := 820; type A is array(1 .. N) of Float; type A3 is array(1 .. 3) of A; procedure F(state : in out A3; result : out A3; l : in A; r : in A) is s : Float; t : Float; begin for i in 1 .. N loop t := l(i) + r(i); t := t / 2.0; state(1)(i) := t; state(2)(i) := t * 0.25 + state(2)(i) * 0.75; state(3)(i) := t * 1.0 /64.0 + state(2)(i) * 63.0 /64.0; for r in 1 .. 3 loop s := state(r)(i); t := FF."**"(s, 6.0) + 14.0; if t > MAX then t := MAX; elsif t < MIN then t := MIN; end if; result(r)(i) := FF.Log(t, 2.0); end loop; end loop; end; psuedocode for testing create two arrays of 80 random A3 arrays, called ls and rs; init the state and result A3 array record the realtime time now, called last for i in 1 .. 100 loop for j in 1 .. 80 loop F(state, result, ls(j), rs(j)); end loop; end loop; record the realtime time now, called curr output the duration between curr and last

    Read the article

  • Creating lots of arrays

    - by Dmitry
    Hello, everybody! May be that is a stupid question. How to create, say, 30 arrays (it doesn't matter of what type, say, char[])? It seems to me that it is not a good idea, to create them one by one by hand. I want to do that using a "for" cycle, but how should I specify identifiers?

    Read the article

  • using Linq to partition data into arrays

    - by user200295
    I have an array of elements where the element has a Flagged boolean value. 1 flagged 2 not flagged 3 not flagged 4 flagged 5 not flagged 6 not flagged 7 not flagged 8 flagged 9 not flagged I want to break it into arrays based on the flagged indicator output array 1 {1,2,3} array 2 {4,5,6,7} array 3 {8,9}

    Read the article

  • Can't concatenate 2 arrays in PHP

    - by alex
    I've recently learned how to join 2 arrays using the + operator in PHP. But consider this code... $array = array('Item 1'); $array += array('Item 2'); var_dump($array); Output is array(1) { [0]= string(6) "Item 1" } Why does this not work? Skipping the shorthand and using $array = $array + array('Item 2') does not work either. Does it have something to do with the keys?

    Read the article

  • Concatenate arrays items

    - by j.
    I have two arrays: x = [ [0, "#0"], [1, "#1"] ] y = [ [00, "00 description"], [10, "10 description"] ] What i need is to merge them so i get the following as result: result = [ [000, "#0 00 description"], [010, "#0 10 description"], [100, "#1 00 description"], [110, "#1 10 description"]] Is there a method for that? Or I'll need to use collect or something like this? Thanks in advance.

    Read the article

  • defining arrays in smarty via config files

    - by quardas
    Is it possible to defining arrays in config files in smarty?? for example I want have small data base in config file (located in /configs) - few (about 20) products descriptions: title, price, description. After that I want to list it via foreach or section. How can I define that array in Smarty without MySql or other db engine. Can I do that?

    Read the article

  • MATLAB image corner coordinates & referncing to cell arrays

    - by James
    Hi, I am having some problems comparing the elements in different cell arrays. The context of this problem is that I am using the bwboundaries function in MATLAB to trace the outline of an image. The image is of a structural cross section and I am trying to find if there is continuity throughout the section (i.e. there is only one outline produced by the bwboundaries command). Having done this and found where the is more than one section traced (i.e. it is not continuous), I have used the cornermetric command to find the corners of each section. The code I have is: %% Define the structural section as a binary matrix (Image is an I-section with the web broken) bw(20:40,50:150) = 1; bw(160:180,50:150) = 1; bw(20:60,95:105) = 1; bw(140:180,95:105) = 1; Trace = bw; [B] = bwboundaries(Trace,'noholes'); %Traces the outer boundary of each section L = length(B); % Finds number of boundaries if L > 1 disp('Multiple boundaries') % States whether more than one boundary found end %% Obtain perimeter coordinates for k=1:length(B) %For all the boundaries perim = B{k}; %Obtains perimeter coordinates (as a 2D matrix) from the cell array end %% Find the corner positions C = cornermetric(bw); Areacorners = find(C == max(max(C))) % Finds the corner coordinates of each boundary [rowindexcorners,colindexcorners] = ind2sub(size(Newgeometry),Areacorners) % Convert corner coordinate indexes into subcripts, to give x & y coordinates (i.e. the same format as B gives) %% Put these corner coordinates into a cell array Cornerscellarray = cell(length(rowindexcorners),1); % Initialises cell array of zeros for i =1:numel(rowindexcorners) Cornerscellarray(i) = {[rowindexcorners(i) colindexcorners(i)]}; %Assigns the corner indicies into the cell array %This is done so the cell arrays can be compared end for k=1:length(B) %For all the boundaries found perim = B{k}; %Obtains coordinates for each perimeter Z = perim; % Initialise the matrix containing the perimeter corners Sectioncellmatrix = cell(length(rowindexcorners),1); for i =1:length(perim) Sectioncellmatrix(i) = {[perim(i,1) perim(i,2)]}; end for i = 1:length(perim) if Sectioncellmatrix(i) ~= Cornerscellarray Sectioncellmatrix(i) = []; %Gets rid of the elements that are not corners, but keeps them associated with the relevent section end end end This creates an error in the last for loop. Is there a way I can check whether each cell of the array (containing an x and y coordinate) is equal to any pair of coordinates in cornercellarray? I know it is possible with matrices to compare whether a certain element matches any of the elements in another matrix. I want to be able to do the same here, but for the pair of coordinates within the cell array. The reason I don't just use the cornercellarray cell array itself, is because this lists all the corner coordinates and does not associate them with a specific traced boundary.

    Read the article

  • How can I marshal a hash with arrays?

    - by tuner
    What should I do to marshal an hash of arrays? The following code only prints {}. s = Hash.new s.default = Array.new s[0] << "Tigger" s[7] << "Ruth" s[7] << "Puuh" data = Marshal.dump(s) ls = Marshal.restore( data ) p ls If the hash doesn't contain an array it is restored properly.

    Read the article

  • how can i pass 2 arrays as datas in googlechart

    - by gin
    I'm using google charts easy php class (here's the link of it) and i want to draw Multiple Vertical Bar Chart, as the documentation says "Separate multiple data sets with |" so i try this , but nothing happens $chart1=new googleChart($a | $b ,'bary' ); *note that both $a & $b are arrays i would appreciate any help :)

    Read the article

  • Relational Database arrays (H2, Java)

    - by Daddy Warbox
    I seem to have two options on how to implement arrays, and I want to know which I should go with: Use the ARRAY data type and (from what I understand) effectively serialize data objects into the database (which in my case are just wrapped primitive types; don't know of another way to make this work). Use a separate table and map with foreign keys for each array item. If you have experience with this (especially with H2), which would you recommend?

    Read the article

  • xCode Adding two arrays together

    - by Frames84
    I call two feeds that both return an NSMutableArray, I then need to make the two arrays into one. NSMutableArray *array1 = [JSONWrapper downloadFeed]; NSMutableArray *array2 = [JSONWrapper downloadFeed]; // something like: array1 += array2 Thanks

    Read the article

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