arrays

How do I create an empty array/matrix in NumPy?

I'm sure I must be being very dumb, but I can't figure out how to use an array or matrix in the way that I would normally use a list. I.e., I want to create an empty array (or matrix) and then add one column (or row) to it at a time. At the moment the only way I can find to do this is like: mat = None for col in columns: if mat is ...

Extracting a subset of values from an associative array (php)

I want to do something seemingly very simple, but I can't find anything about it: simply extract a subset of an array similar to array_splice, but using keys to retrieve the values : $data = array('personName' => 'John', 'personAge' => 99, 'personId' => 1, /* many more data I don't need here ... */); list($name, $age, $...

count duplicate elements in ruby array

I have an sorted array like this: ['FATAL <error title="Request timed out.">', 'FATAL <error title="Request timed out.">', 'FATAL <error title="There is insufficient system memory to run this query.">'] I would like to get something like this (does not have to be a hash): [{:error => 'FATAL <error title="Request timed out.">', :count...

GetMem x ReallocMem

What is the difference between System.GetMem and System.ReallocMem? Delphi 2009 Help for ReallocMem, is exactly the same description of GetMem. How about System.FreeMem and System.Dispose What should I use with arrays? type PMemberDataList = ^TMemberDataList; TMemberDataList = array[0..MaxClassMembers -1] of PMemberData; var F...

Best practice when returning an array of values (.NET)

Usually my methods are as the following: public List<int> Method1(int input) { var output = new List<int>(); //add some items to output return output; } But FxCop advises another IList implementation instead of List, but I can't remember which. The alternatives include returning it as an IList, ICollection or IEnumerable f...

Converting an array of bytes to an array of floats

I'm currently converting a Delphi method used for random binary file access into Java. The Delphi procedure uses: TSingleArray = Array[0..MAXSIZE] of Single ... procedure GetLinkValues(const LinkVar: Integer; const TimePeriod: Integer; var Value: PSingleArray); ... BlockRead(Fout, Value^, Nlinks*SizeOf(Single)); To read an array of...

What is the jQuery equivelent of mootools Array.include() ?

I'm trying to add an element to an array only if it doesn't already exist in the array. I used to do this with the Array.include method of mootools, but now I'm using jquery. Is there a method to do this in jquery? http://mootools.net/docs/Native/Array#Array:include ...

Getting a stack overflow exception when declaring a large array

The following code is generating a stack overflow error for me int main(int argc, char* argv[]) { int sieve[2000000]; return 0; } How do I get around this? I am using Turbo C++ but would like to keep my code in C EDIT: Thanks for the advice. The code above was only for example, I actually declare the array in a function and...

Javascript - How to extend Array.prototype.push()?

I'm trying to extend the Array.push method so that using push will trigger a callback method, then perform the normal array function. I'm not quite sure how to do this, but here's some code I've been playing with unsuccessfully. arr = []; arr.push = function(data){ //callback method goes here this = Array.push(data); return this.l...

ArrayList versus an array of objects versus Collection of T

I have a class named Customer (with typical customer properties) and I need to pass around, and databind, a "chunk" of Customer instances. Currently I'm using an array of Customer, but I've also used Collection of T (and List of T before I knew about Collection of T). I'd like the thinnest way to pass this chunk around using C# and .NET ...

Is the size of an array constrained by the upper limit of int (2147483647)?

I'm doing some Project Euler exercises and I've run into a scenario where I have want arrays which are larger than 2,147,483,647 (the upper limit of int in C#). Sure these are large arrays, but for instance, I can't do this // fails bool[] BigArray = new BigArray[2147483648]; // also fails, cannot convert uint to int ArrayList BigAr...

How to remove elements from array but effectively shift down everything else in the array?

Given a file compact.txt that contains no more than 100 integers greater than 0, you need to read the file into an array, then traverse the array removing all the zeros keeping the original order of numbers in tact. And below is my unfinished code. import java.io.File; import java.util.Scanner; public class CompactUtil { private st...

NSMutable NSArray Array - How can I avoid all these lines and use a dimensional or 3D array?

enter code here- (void)viewDidLoad { NSMutableArray *imageViewArray= [[NSMutableArray alloc] init]; for ( int i = 1; i < 10 ; i++ ) { NSString *imgName = [NSString stringWithFormat:@"pic%i.jpg", i]; UIImage *img = [UIImage imageNamed:imgName]; [imageViewArray addObject:img]; } self.gallery = imageViewArray; [imageViewArray release]...

Constructor for class

Arrays in C/C++ of N elements have subscripts from 0 as the lower bound to N-1 as the upper bound. Other languages like Pascal allow the user to specify any lower bound and upper bound subscript values to create an array of (upper bound - lower bound + 1) elements. Question: Create a class "Array" in C++ that allows a user to specify bo...

OCR: How to compare images, sort unmatching out and do this fast?

Hi, I managed to have each character stored in a bitmap and am looking for a way to quickly determine which character it is. Therefore I'm about to store every possible character into an array of 1 and 0, and compare them to an array of the bitmap I just grabbed. I could do simple checks like compare how many black pixels I got, compa...

Associative arrays in javascript

I have this object: function formBuddy() { var fields = new Array(); var labels = new Array(); var rules = new Array(); var count=0; this.addField = function(field, label, rule) { fields[count] = field; labels[field] = label; rules[field] = rule; count = ++count; } } Its use...

Count array counts 1 too many

Does anyone know how to get arround the annoying problem that when counting how many values there is inside an array if the value is 0 it says 1 becuase it counts the name or something. So like this: 0 : 1 1 : 1 2 : 2 3 : 3 4 : 4 5 : 5 6 : 6 7 : 7 8 : 8 Thnaks, Stanni ...

Adding Matrices in C#?

I'm trying to add two matrices together in C# using some simple for loops. I store the results in a data grid view. However, the last cell does not seem to add. I've been looking at this code for a while now and can't seem to figure it out. Did I do something wrong? // Adds two matrices together using arrays. private void menuIt...

How do I fill arrays in Java?

I know how to do it normally, but I could swear that you could fill out out like a[0] = {0,0,0,0}; How do you do it that way? I did try Google, but I didn't get anything helpful. ...

Saving an array value into a double variable

Greetings everyone. Having an issue compiling my script containing the following function. Three errors occur, all on the same line where I set distance += to distances [][]: error C2108: subscript is not of integral type error C2108: subscript is not of integral type error C2297: '+=' : illegal, right operand has type 'double (*)[15]' ...