arrays

Sum one row of a NumPy array

I'd like to sum one particular row of a large NumPy array. I know the function array.max() will give the maximum across the whole array, and array.max(1) will give me the maximum across each of the rows as an array. However, I'd like to get the maximum in a certain row (for example, row 7, or row 29). I have a large array, so getting the...

C# Array Conversion

Any help here as I'm a C# noob. The following code works fine and returns 1 string ViewState2. I'd like it to return an array of ViewState2 and EventValidation2 so I can manipulate it later on. How would I convert the code below to return an array? public string get_status(string local_fname) { var dts_doc = new HtmlA...

Using Recursion to Flatten a PHP Array with Subitems Based on Values (Wasted an Hour on This!)

I'm trying to build a navigation menu. I am receiving an array with a structure like this: [ [ Title = A Sub items = [ Title = B Sub items = [ Title = C ] ] ], [ Title = A Sub items = [ Title = B Sub items = [ Title = D ] ] ], ] I need to take it and ...

Creating Multidimenional Arrays

How can I add arrays into an existing array item? For instance: $user[$user->id] = array(//values); But if that user needs another array added, I want all data to fall under that user ID in the array. I want to store orders a user has made, so I can look up all orders on the fly by user ID in the $user array above. ...

Access Variable variables with an object

Hello, I don't really know how to decribe this problem, so I'm sorry if the title is a bit unclear. I got an object with array fields. I got the name of these fields stored in a variable and I want to reach an element in one of those array fields. e.g. $field_name = 'array_field'; $object = new stdClass(); $object->array_field= array...

jquery arrays intersect

Hi, I previously posted this question as jquery/javascript: arrays - http://stackoverflow.com/questions/3969576/jquery-javascript-arrays. But since I am a complete beginner I have formulated the question wrong and didn't understand the answers either.... :( After failing to implement the given solutions I did some more looking around I...

More elegant way to check for duplicates in C++ array?

I wrote this code in C++ as part of a uni task where I need to ensure that there are no duplicates within an array: // Check for duplicate numbers in user inputted data int i; // Need to declare i here so that it can be accessed by the 'inner' loop that starts on line 21 for(i = 0;i < 6; i++) { // Check each other number in the ...

How do I hash a 2-d array efficiently (to be stored in a HashSet)?

I've written a class called PuzzleBoard that represents an nxn board. I will be keeping several PuzzleBoard objects in a HashSet, so I have to overwrite the 'int hashCode()' method. Below are the fields of my class: private int N; private int[][] puzzle; private int blankCellX; private int blankCellY; private int cost; What Ecli...

Advantages of using arrays instead of std::vector?

I'm currently seeing a lot of questions which are tagged C++ and are about handling arrays. There even are questions which ask about methods/features for arrays which a std::vector would provide without any magic. So I'm wondering why so much developers are chosing arrays over std::vector in C++? ...

MongoDB and Java Objects

Hi, I have the following MongoDB object stored in my Mongo database: array ( '_id' => new MongoId("4cc183de48aa4c7708000000"), 'vehicleMake' => 'Volkswagen', 'vehicleModel' => 'Carrier', 'vehicleNumPassengers' => '7', 'vehicleReg' => '07-D-748393', 'coords' => array ( 0 => array ( 'lat' => '53.2594946', ...

randomise a two-dimensional array with chars?

Is this code a good solution to randomise a two-dimensional array and write out all the symbols on the screen? If you have a better tip or solution please tell me. int slumpnr; srand( time(0) ); char game[3][3] = {{'O','X','A'}, {'X','A','X'}, {'A','O','O'}}; for(int i = 0 ; i < 5 ; i++) { slumpnr = rand()%3; if(slumpnr == 1) ...

Why is my Perl loop off by one at the end?

I have this program which does not work as expected. Help me. I want to print a row heading. If input is 4, I want 1|2|3|4 to be output. It does not work as all, if I hard-code $count value it works partially but the last number is missing. sub printC { my $count = @_; # count = 4 # works partially only prints 1|2|3 ...

Java 2D Arrays Question

If I have a 2D array, arr[][], and let say I do this: arr[0]=10; What does this do? I only assigned 10 in the first dimension, but I didnt mention the second dimension. What happens in this case? Edit: Ok what about this: public static int[][] mystery(int[][] srcA, int[][] srcB) { 2 int width= srcA.length, height = srcA[0].length;...

How to output a the contents of an array selectively with a IF statement

I have having some trouble printing a "char" from an ASCII value stored in an array. The goal overall is to read a string of input from the user, store that in an array. Then use another array to count the number of times each character appears in the string, storing the number of occurances in the array address that matches the ASCII c...

When you use document.getElementsByTagName() in javascript do you get an array of all the elements?

I have this document.getElementsByTagName('input') to get all the <input> elements on the page. will this result in an array that I can put a for loop through? ...

Getting NullPointerException when accessing a variable in a Java class

Hi guys, I have a problem when setting a variable inside a Java class Here is my code This is where I create the instances (IdeaInfo is a class that acts similar to a Struct): IdeaInfo[] IDEAS = new IdeaInfo[100]; String[] TITLES = new String[100]; This is the function that will use those instances: try { while ((line ...

File[] to String[]

The title is basically all there is too it. I have an array of file objects... File[] myFiles = myDirectory.listFiles(); And I want to convert it to an array of strings. (String[]) ...

C negative array index

this is my struct : struct Node { struct Node* data; struct Node* links[4]; } assuming there is no padding, does Node->links[-1] guaranteed to be pointing on Node::data ? ...

PHP max() with an array of strings?

Hi all I have an array of tags taken from a MySQL database. Obviously, these tags are strings and are stored in an array, with one element in the array storing each tag. TO build my tag cloud, I want to be able to count the occurrences of each tag to find the most common tag. For example, if I have the table below... tag1 tag1 hi bye...

how to do a "flat push" in javascript?

I want to push all individual elements of a source array onto a target array, tartget.push(source); puts just source's reference on the target list. In stead I want to do: for (i=0;i<source.length;i++) { target.push(source[i]); } Is there a way in javascript to do this more elegant, without explicitly coding a repetition loop?...