Search Results

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

Page 13/142 | < Previous Page | 9 10 11 12 13 14 15 16 17 18 19 20  | Next Page >

  • How do you construct an array suitable for numpy sorting?

    - by Alex
    I need to sort two arrays simultaneously, or rather I need to sort one of the arrays and bring the corresponding element of its associated array with it as I sort. That is if the array is [(5, 33), (4, 44), (3, 55)] and I sort by the first axis (labeled below dtype='alpha') then I want: [(3.0, 55.0) (4.0, 44.0) (5.0, 33.0)]. These are really big data sets and I need to sort first ( for nlog(n) speed ) before I do some other operations. I don't know how to merge my two separate arrays though in the proper manner to get the sort algorithm working. I think my problem is rather simple. I tried three different methods: import numpy x=numpy.asarray([5,4,3]) y=numpy.asarray([33,44,55]) dtype=[('alpha',float), ('beta',float)] values=numpy.array([(x),(y)]) values=numpy.rollaxis(values,1) #values = numpy.array(values, dtype=dtype) #a=numpy.array(values,dtype=dtype) #q=numpy.sort(a,order='alpha') print "Try 1:\n", values values=numpy.empty((len(x),2)) for n in range (len(x)): values[n][0]=y[n] values[n][1]=x[n] print "Try 2:\n", values #values = numpy.array(values, dtype=dtype) #a=numpy.array(values,dtype=dtype) #q=numpy.sort(a,order='alpha') ### values = [(x[0], y[0]), (x[1],y[1]) , (x[2],y[2])] print "Try 3:\n", values values = numpy.array(values, dtype=dtype) a=numpy.array(values,dtype=dtype) q=numpy.sort(a,order='alpha') print "Result:\n",q I commented out the first and second trys because they create errors, I knew the third one would work because that was mirroring what I saw when I was RTFM. Given the arrays x and y (which are very large, just examples shown) how do I construct the array (called values) that can be called by numpy.sort properly? *** Zip works great, thanks. Bonus question: How can I later unzip the sorted data into two arrays again?

    Read the article

  • Sort an array by a child array's value

    - by Evan
    I have an array composed of arrays. I want to sort the parent array by a property of the child arrays. Here's an example array(2) { [0]=> array(3) { [0]=> string(6) "105945" [1]=> string(10) "First name" [2]=> float(0.080878465391) } [1]=> array(3) { [0]=> string(6) "109145" [1]=> string(11) "Second name" [2]=> float(0.0504154818384) } I would like to sort the parent array by [2] ascending in the child arrays, so in this case the result would be the child arrays reversed (.05, 08). Is this possible using any of the numerous PHP sort functions?

    Read the article

  • Grails - Where to store properties related to domains

    - by GalmWing
    This is something I have been struggling about for some time now. The thing is: I have many (20 or so) static arrays of values. I say static because that is how I'm actually storing them, as static arrays inside some domains. For example, if I have a list of known websites, I do: class Website { ... static websites = ["web1", "web2" ...] } But I do this just while developing, because I can easily change the arrays if needed, but what I'm going to do when the application is ready for deployment? In my project it is very probable that, at some point, these arrays of values change. I've been researching on that matter, one can store application properties inside an external .properties file, but it will be impossible to store an array, even futile, because if some array gets an additional value, the application can't recognize it until the name of the new property is added where needed. Another approach is to store this information in the database, but for some reason it seems like a waste to add 20 or more tables that will have just two rows, an id and a name. And the last option, as far as I know, would be an XML, but I'm not very experienced with those. It seems groovy has a way of creating and reading XML files relatively easy, but I don't know how difficult would be to modify an XML whose layout is predefined in the application. Needless to say that storing them in the config.groovy is not an option since any change will require to recompile. I haven't come across some "standard" (maybe a best practice?) way of dealing with these. So the questions is: Where to store these arrays?

    Read the article

  • Compare array in loop

    - by user3626084
    I have 2 arrays with different sizes, in some cases one array can have more elements than the other array. However, I always need to compare the arrays using the same id. I need to get the other value with the same id in the other array I have tried this, but the problem happens when I compare the two arrays in a loop when the other array has more elements than one, because duplicate the loop and data , and it does not work. Here is what I've tried: <?php /// Actual Data Arrays /// $data_1=array("a1-fruits","b1-apple","c1-banana","d1-chocolate","e1-pear"); $data_2=array("b1-cars","e1-eggs"); /// for ($i=0;$i<count($data_1);$i++) { /// Explode ID $data_1 /// $exp_id=explode("-",$data_1[$i]); /// for ($h=0;$h<count($data_2);$h++) { /// Explode ID $data_2 /// $exp_id2=explode("-",$data_2[$h]); /// if ($exp_id[0]=="".$exp_id2[0]."") { print "".$data_2[$h].""; print "<br>"; } else { print "".$data_1[$i].""; print "<br>"; } /// } /// } ?> I want the following values : "a1-fruits" "b1-cars" "c1-banana" "d1-chocolate" "e1-eggs" Yet, I get this (which isn't what I want): a1-fruits a1-fruits b1-cars b1-apple c1-banana c1-banana d1-chocolate d1-chocolate e1-pear e1-eggs I tried everything I know and try to understand how I can do this because I don't understand how to compare these two arrays. The other problem is when one size has more elements than the other, the comparison always gives an error. I FIND THE SOLUTION TO THIS AND WORKING IN ALL : <?php /// Actual Data Arrays /// $data_1=array("a1-fruits","b1-apple","c1-banana","d1-chocolate","e1-pear"); $data_2=array("b1-cars","e1-eggs","d1-chocolate2"); /// for ($i=0;$i<count($data_1);$i++) { $show="bad"; /// Explode ID $data_1 /// $exp_id=explode("-",$data_1[$i]); /// for ($h=0;$h<count($data_2);$h++) { /// Explode ID $data_2 /// $exp_id2=explode("-",$data_2[$h]); /// if ($exp_id2[0]=="".$exp_id[0]."") { $show="ok"; print "".$data_2[$h]."<br>"; } /// } if ($show=="bad") { print "".$data_1[$i].""; print "<br>"; } /// } ?>

    Read the article

  • How to iterate & retrieve values from NSArray of NSArrays of NSDictionaries

    - by chinjazz
    I'm stumpped on how iterate and get values for an Array of Arrays of NSDictionaries (different classes/entities). Here's what I'm currently doing: 1) Constructing two separate arrays of NSDictionaries (different entities) 2) Combining both arrays with: NSMutableArray *combinedArrayofDicts = [[NSMutableArray alloc] initWithObjects: sizesArrayOfDicts, wishListArrayOfDicts , nil]; 3) Then archive combinedArrayofDicts : NSData *dataToSend = [NSKeyedArchiver archivedDataWithRootObject:combinedArrayofDicts]; 4) Transmit over GameKit [self.session sendDataToAllPiers:dataToSend withDataMode: GKSendDataReliable error:nil]; 5) How would I manage traversing thru this array on the receiving end? I want to fetch values by for each class which is key'ed by classname: Here's how it looks via NSLog (2 Sizes Dicts, and 1 Wishlist Dict) Printing description of receivedArray: <__NSArrayM 0xbc65eb0>( <__NSArrayM 0xbc651f0>( { classname = Sizes; displayOrder = 0; share = 1; sizeType = Neck; value = "13\" or 33 (cm)"; }, { classname = Sizes; displayOrder = 0; share = 1; sizeType = Sleeve; value = "34\" or 86 (cm)"; } ) , <__NSArrayM 0xbc65e80>( { classname = Wishlist; detail = ""; displayOrder = 0; imageString = ""; latitude = "30.33216666666667"; link = "http://maps.google.com/maps?q=loc:30.332,-81.41"; longitude = "-81.40949999999999"; name = bass; share = 1; store = ""; } ) ) (lldb) In my for loop I'm issuing this: NSString *value = [dict objectForKey:@"classname"]; and get an exception: * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSArrayM objectForKey:]: unrecognized selector sent to instance 0xbc651f0' Is this frowned upon as far as mixing object types in arrays of arrays?

    Read the article

  • I need to modify a program to use arrays and a method call. Should I modify the running file, the data collection file, or both?

    - by g3n3rallyl0st
    I have to have multiple classes for this program. The problem is, I don't fully understand arrays and how they work, so I'm a little lost. I will post my program I have written thus far so you can see what I'm working with, but I don't expect anyone to DO my assignment for me. I just need to know where to start and I'll try to go from there. I think I need to use a double array since I will be working with decimals since it deals with money, and my method call needs to calculate total price for all items entered by the user. Please help: RUNNING FILE package inventory2; import java.util.Scanner; public class RunApp { public static void main(String[] args) { Scanner input = new Scanner( System.in ); DataCollection theProduct = new DataCollection(); String Name = ""; double pNumber = 0.0; double Units = 0.0; double Price = 0.0; while(true) { System.out.print("Enter Product Name: "); Name = input.next(); theProduct.setName(Name); if (Name.equalsIgnoreCase("stop")) { return; } System.out.print("Enter Product Number: "); pNumber = input.nextDouble(); theProduct.setpNumber(pNumber); System.out.print("Enter How Many Units in Stock: "); Units = input.nextDouble(); theProduct.setUnits(Units); System.out.print("Enter Price Per Unit: "); Price = input.nextDouble(); theProduct.setPrice(Price); System.out.print("\n Product Name: " + theProduct.getName()); System.out.print("\n Product Number: " + theProduct.getpNumber()); System.out.print("\n Amount of Units in Stock: " + theProduct.getUnits()); System.out.print("\n Price per Unit: " + theProduct.getPrice() + "\n\n"); System.out.printf("\n Total cost for %s in stock: $%.2f\n\n\n", theProduct.getName(), theProduct.calculatePrice()); } } } DATA COLLECTION FILE package inventory2; public class DataCollection { String productName; double productNumber, unitsInStock, unitPrice, totalPrice; public DataCollection() { productName = ""; productNumber = 0.0; unitsInStock = 0.0; unitPrice = 0.0; } //setter methods public void setName(String name) { productName = name; } public void setpNumber(double pNumber) { productNumber = pNumber; } public void setUnits(double units) { unitsInStock = units; } public void setPrice(double price) { unitPrice = price; } //getter methods public String getName() { return productName; } public double getpNumber() { return productNumber; } public double getUnits() { return unitsInStock; } public double getPrice() { return unitPrice; } public double calculatePrice() { return (unitsInStock * unitPrice); } }

    Read the article

  • Variable number of two-dimensional arrays into one big array

    - by qlb
    I have a variable number of two-dimensional arrays. The first dimension is variable, the second dimension is constant. i.e.: Object[][] array0 = { {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"}, {"alice", "smith", 42, 160.0, "la", "bub", "[email protected]"}, ... }; Object[][] array1 = { {"john", "sdfs", 34, 15.5, "a", "bl", "[email protected]"}, {"joe", "smith", 42, 16.0, "a", "bub", "[email protected]"}, ... }; ... Object[][] arrayi = ... I'm generating these arrays with a for-loop: for (int i = 0; i < filter.length; i++) { MyClass c = new MyClass(filter[i]); //data = c.getData(); } Where "filter" is another array which is filled with information that tells "MyClass" how to fill the arrays. "getData()" gives back one of the i number of arrays. Now I just need to have everything in one big two dimensional array. i.e.: Object[][] arrayComplete = { {"tim", "sanchez", 34, 175.5, "bla", "blub", "[email protected]"}, {"alice", "smith", 42, 160.0, "la", "bub", "[email protected]"}, ... {"john", "sdfs", 34, 15.5, "a", "bl", "[email protected]"}, {"joe", "smith", 42, 16.0, "a", "bub", "[email protected]"}, ... ... }; In the end, I need a 2D array to feed my Swing TableModel. Any idea on how to accomplish this? It's blowing my mind right now.

    Read the article

  • Java: creating objects of arrays with different names at runtime and accessing/updating them

    - by scriptingalias
    Hello, I'm trying to create a class that can instantiate arrays at runtime by giving each array a "name" created by the createtempobjectname() method. I'm having trouble making this program run. I would also like to see how I could access specific objects that were created during runtime and accessing those arrays by either changing value or accessing them. This is my mess so far, which compiles but gets a runtime exception. import java.lang.reflect.Array; public class arrays { private static String temp; public static int name = 0; public static Object o; public static Class c; public static void main(String... args) { assignobjectname(); //getclassname();//this is supposed to get the name of the object and somehow //allow the arrays to become updated using more code? } public static void getclassname() { String s = c.getName(); System.out.println(s); } public static void assignobjectname()//this creates the object by the name returned { //createtempobjectname() try { String object = createtempobjectname(); c = Class.forName(object); o = Array.newInstance(c, 20); } catch (ClassNotFoundException exception) { exception.printStackTrace(); } } public static String createtempobjectname() { name++; temp = Integer.toString(name); return temp; } }

    Read the article

  • C++ Boolean problem (comparison between two arrays)

    - by Martin
    Hello! I have a problem to do. I already did some part of it, however I stuck and don't know exactly what to do next. The question: " You are given two arrays of ints, named A and B. One contains AMAXELEMENTS and the other contains BMAXELEMENTS. Write a Boolean-valued function that returns true if there is at least one point in A that is the same as a point in B, and false if there is no match between two arrays. " The two arrays are made up by me, I think if I know how to compare two arrays I will be fine, and I will be able to finish my problem. This is what I have so far (I changed AMAXELEMENTS to AMAX, and BMAXELEMENTS to BMAX): #include <iostream> using namespace std; int main(){ const int AMAX=5, BMAX=6; int i; bool c1=true,c2=false; int A[AMAX]={2,4,1,5,9}; int B[BMAX]={9,12,32,43,23,11}; for(i=0;i<BMAX;i++) if (B[i]==A[i]) // <---- I think this part has to look different, but I can't figure it out. cout<<c1<<endl; else cout<< c2<<endl; return 0; }

    Read the article

  • Multidimensional arrays in VB.NET 2010

    - by matt_t
    Is there any way to create a multidinensional array that contains arrays of different lengths (similar to nesting arrays of different lengths in python). Because if I were to declare a variable Dim accounts(2,2) As Integer all 1D arrays at each dimension have the same length. Is there any way to create an array so that this is not the case? e.g The above code would create an array like this: [[0,0],[0,0]] but would it be possible to create this: [[0,0],[0,0,0]] Apologies for the poor explanation but I cannot think of any better ways to explain.

    Read the article

  • Visual Studio XSD Tool: Generate Collections Rather Than Arrays

    - by senfo
    I generated some C# classes from an XSD using the Visual Studio XSD utility and it generated arrays for storing a collection of elements, rather than one of the built-in generic Collection<T> (or related) classes. None of the command line parameters mentioned in xsd /? mention anything about generating collections rather than arrays, but I know that this can be done with web service proxy classes that Visual Studio generates, so I figured it must be possible. Does anybody know how to have the XSD utility generate collection classes rather than arrays?

    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

  • Excel VBA pass array of arrays to a function

    - by user429400
    I have one function that creates an array of arrays, and one function that should get the resulting array and write it to the spreadsheet. I don't find the syntax which will allow me to pass the array of arrays to the second function... Could you please help? Here is my code: The function that creates the array of arrays: Function GetCellDetails(dict1 As Dictionary, dict2 As Dictionary) As Variant Dim arr1, arr2 arr1 = dict1.Items arr2 = dict2.Items GetCellDetails = Array(arr1, arr2) End Function the function that writes it to the spreadsheet: Sub WriteCellDataToMemory(arr As Variant, day As Integer, cellId As Integer, nCells As Integer) row = CellIdToMemRow(cellId, nCells) col = DayToMemCol(day) arrSize = UBound(arr, 2) Range(Cells(row, col), Cells(row + arrSize , col + 2)) = Application.Transpose(arr) End Sub The code that calls the functions: Dim CellDetails CellDetails = GetCellDetails(dict1, dict2) WriteCellDataToMemory CellDetails, day, cellId, nCells Thanks, Li

    Read the article

  • Large static arrays are slowing down class load, need a better/faster lookup method

    - by Visualize
    I have a class with a couple static arrays: an int[] with 17,720 elements a string[] with 17,720 elements I noticed when I first access this class it takes almost 2 seconds to initialize, which causes a pause in the GUI that's accessing it. Specifically, it's a lookup for Unicode character names. The first array is an index into the second array. static readonly int[] NAME_INDEX = { 0x0000, 0x0001, 0x0005, 0x002C, 0x003B, ... static readonly string[] NAMES = { "Exclamation Mark", "Digit Three", "Semicolon", "Question Mark", ... The following code is how the arrays are used (given a character code). [Note: This code isn't a performance problem] int nameIndex = Array.BinarySearch<int>(NAME_INDEX, code); if (nameIndex > 0) { return NAMES[nameIndex]; } I guess I'm looking at other options on how to structure the data so that 1) The class is quickly loaded, and 2) I can quickly get the "name" for a given character code. Should I not be storing all these thousands of elements in static arrays?

    Read the article

  • Finding the sum of 2D Arrays in Ruby

    - by Bragaadeesh
    Hi, I have an array of two dimensional Arrays. I want to create a new two dimensional array which finds the sum of these values in the 2D arrays. Sum at x,y of new array = Sum at x,y of arr1 + Sum at x,y of arr2 + .... |1,2,4| |1,1,1| |1,1,1| |2,4,6| |1,1,1| |1,1,1| |2,4,6| |1,1,1| |1,1,1| |2,4,6| |1,1,1| |1,1,1| Now adding the above two dimensional arrays will result in, |3,4,6| |4,6,8| |4,6,8| |4,6,8| How to achieve this in Ruby (not in any other languages). I have written a method, but it looks very long and ugly.

    Read the article

  • Bash scripting - Iterating through "variable" variable names for a list of associative arrays

    - by user1550254
    I've got a variable list of associative arrays that I want to iterate through and retrieve their key/value pairs. I iterate through a single associative array by listing all its keys and getting the values, ie. for key in "${!queue1[@]}" do echo "key : $key" echo "value : ${queue1[$key]}" done The tricky part is that the names of the associative arrays are variable variables, e.g. given count = 5, the associative arrays would be named queue1, queue2, queue3, queue4, queue5. I'm trying to replace the sequence above based on a count, but so far every combination of parentheses and eval has not yielded much more then bad substitution errors. e.g below: for count in {1,2,3,4,5} do for key in "${!queue${count}[@]}" do echo "key : $key" echo "value : ${queue${count}[$key]}" done done Help would be very much appreciated!

    Read the article

  • seprate a string array to several small arrays

    - by blgnklc
    how can I separate an array in smaller arrays? string[] str = new string[145] I want two arrays for this; like string[] str1 = new string[99]; string[] str2 = new string[46]; how can I do this from the source of str? 1- Then I want to put togetger the arrays into List all together but there is only add item? no add items? or any other way to make the string[145] array again..

    Read the article

  • comparing 3 arrays and result in 1 array

    - by frightnight
    i have 3 arrays, i want to get the result of those 3 arrays in one, but how can i deleted those same answer in a arrays? here's my example: <?php $array1 = array("a" => "green", "red", "blue"); $array2 = array("b" => "green", "yellow", "red"); $array3 = array("c" => "white", "blue", "black"); $result = ??? ($array1, $array2, $array3); print_r($result); ?> Array ( [0] => green [1] => red [2] => blue [3] => yellow [4] => red [5] => white [5] => black ) please help me guys.. thank you..

    Read the article

  • Does LaTeX have an array data structure?

    - by drasto
    Are there arrays in LaTeX? I don't mean the way to typeset arrays. I mean arrays as the data structure in LaTeX/TeX as a "programming language". I need to store a number of vbox-es or hbox-es in an array. It may be something like "an array of macros". More details: I have an environment that should typeset songs. I need to store some songs' paragraphs given as arguments to my macro \songparagraph (so I will not typeset them, just store those paragraphs). As I don't know how many paragraphs can be in one particular song I need an array for this. When the environment is closed, all the paragraphs will be typeset - but they will be first measured and the best placement for each paragraph will be computed (for example, some paragraphs can be put one aside the other in two columns to make the song look more compact and save some space). Any ideas would be welcome. Please, if you know about arrays in LaTeX, post a link to some basic documentation, tutorial or just state basic commands.

    Read the article

  • Data Structures for Junior Java Developer

    - by user1639637
    Ok,still learning Arrays. I wrote this code which fills the array named "rand" with random numbers between 0 and 1( exclusive). I want to start learning Complexity. the For loop executes n times (100 times) ,every time it takes O(1) time,so the worse case scenario is O(n),am I right? Also,I used ArrayList to store the 100 elements and I imported "Collections" and used Collections.sort() method to sort the elements. import java.util.Arrays; public class random { public static void main(String args[]) { double[] rand=new double[10]; for(int i=0;i<rand.length;i++) { rand[i]=(double) Math.random(); System.out.println(rand[i]); } Arrays.sort(rand); System.out.println(Arrays.toString(rand)); } } ArrayList: import java.util.ArrayList; import java.util.Collections; public class random { public static void main(String args[]) { ArrayList<Double> MyArrayList=new ArrayList<Double>(); for(int i=0;i<100;i++) { MyArrayList.add(Math.random()); } Collections.sort(MyArrayList); for(int j=0;j<MyArrayList.size();j++) { System.out.println(MyArrayList.get(j)); } } }

    Read the article

  • Two Raid-1 arrays in a single system?

    - by DebAtCQ
    I'm building a Raid array for the first time in my system and I have a question regarding having multiple Raid-1 arrays in a single Win 7 system. I'm a bit of an organizational freak with my data and I currently have two separate hard drives I want to mirror. The new motherboard I'm looking to buy supports Raid, so my questions are: Can I have more than one Raid-1 array in a single system? Would I have to buy a separate controller for the second array?

    Read the article

  • Converting array to list in Java

    - by Alexandru
    How do I convert an array to a list in Java? I used the Arrays.asList() but the behavior (and signature) somehow changed from 1.4.2 to 1.5.0 and most snippets I found on the web use the 1.4.2 behaviour. For example: int[] spam = new int[] { 1, 2, 3 }; Arrays.asList(spam) on 1.4.2 returns a list containing the elements 1, 2, 3 on 1.5.0 returns a list containing the array spam In many cases it should be easy to detect, but sometimes it can slip unnoticed: Assert.assertTrue(Arrays.asList(spam).indexOf(4) == -1);

    Read the article

  • Jagged Array Dimensions

    - by Soo
    I'm using jagged arrays and have a bit of a problem (or at least I think I do). The size of these arrays are determined by how many rows are returned in a database, so it is very variable. The only solution I have is to set the dimensions of the array to be very huge, but this seems ... just not the best way to do things. int[][] hulkSmash = new int[10][]; hulkSmash[0] = new int[2] {1,2}; How can I work with jagged arrays without setting the dimensions, or is this just a fact of life with C# programming??

    Read the article

  • Merge array in a different way in PHP

    - by user2984974
    I have these two arrays: $array1 = array( '0' => 'apple', '1' => '' , '2' => 'cucumber' ); $array2 = array( '0' => '', '1' => 'bmw', '2' => 'chrysler' ); if I do this to merge these arrays: $result_arr = array_merge($array1, $array2); print_r( count ( array_filter($result_arr) ) ); the output would be 4. However, I need to get the number 3. So, when there are two things on the same position (same key) count it only once. Is it possible to merge/count elements in arrays like that?

    Read the article

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