2d-array

Get adjacent elements in a two-dimensional array?

I have a two-dimensional array, say 0 0 0 0 0 0 2 3 4 0 0 9 1 5 0 0 8 7 6 0 0 0 0 0 0 And i need to get all the numbers adjacent to 1(2, 3, 4, 5, 6, 7, 8, 9) Is there a less ugly solution than: topLeft = array[x-1][y-1] top = array[x][y-1] topRight = array[x+1][y-1] # etc Thanks! ...

Creating 2D-array from array with foreach-loops.

Hi, sorry for the vague title. I'm extracting some data from a table with the setup as specified below, using simple_html_dom. What I want to do is insert the data into a 2D-array (?), where the value of the first -field is the name of a subscription and the rest is data relevant to that subscription. <td><a href="/subname/index.jsp">Su...

Python - best way to set a column in a 2d array to a specific value

Hi I have a 2d array, I would like to set a column to a particular value, my code is below. Is this the best way in python? rows = 5 cols = 10 data = (rows * cols) *[0] val = 10 set_col = 5 for row in range(rows): data[row * cols + set_col - 1] = val If I want to set a number of columns to a particular value , how could I exten...

passing statically allocated 2D arrays as function arguments in C

Hi All, Consider this code: #include <stdio.h> #define N 5 void printMatrix(int (*matrix)[N],int n) { int i,j; for(i=0;i<n;i++){ for(j=0;j<n;j++) printf("%d",matrix[i][j]); printf("\n"); } } int main() { int R[N][N]={{1,2,3},{4,5,6},{7,8,9}}; printMatrix(R,3); } This works fine as expected. Now, I...

Passing pointer to 2D array c++

I'm having this problem for quite a long time - I have fixed sized 2D array as a class member. class myClass { public: void getpointeM(...??????...); double * retpointM(); private: double M[3][3]; }; int main() { myClass moo; double *A[3][3]; moo.getpointM( A ); ??? A = moo.retpointM(); ??? ...

Language to define references between elements in a 2D array/grid.

Has someone created a language which can be used to track/analyze dependencies between grid cells in a generic way? I'm trying to write a spreadsheet which uses a functional language. What I'm after is something similar to what Excel might use to manage references between cells. The language will be used create a model which can be anal...

How do you make a 2-d array in Matlab?

I want to make a 2D array dij(i and j are subscripts). I want to be able to do dij = di,j-1+(di,j-1 - di-1,dj-1)/(4^j-1) My idea for this it to make to 1D arrays and then combine them into a 2D array. Is there an easier way to do this? ...

2d array, using calloc in C

Hi, I'm trying to create a 2D array of chars to storage lines of chars. For Example: lines[0]="Hello"; lines[1]="Your Back"; lines[2]="Bye"; Since lines has to be dynamically cause i don't know how many lines i need at first. Here is the code i have: int i; char **lines= (char**) calloc(size, sizeof(char*)); for ( i = 0; i < size; ...

Visit neighbor of a position in a 2d-array

I have the following two dimensional array: static int[,] arr = new int[5, 5] { { 00, 00, 00, 01, 00 }, { 00, 00, 01, 01, 00 }, { 00, 00, 01, 01, 00 }, { 00, 00, 01, 01, 00 }, { 00, 00, 00, 01, 00 }, }; I have to a implement a method called Hit(int x, int y). When we hit a 0 in the array (i.e. Hit(0, 0), Hit(1, 1...

initialising a 2-dim Array in Scala

(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) ...

Sorting 2D array of chars C++

I have a 2d array of chars where in each row I store a name... such as this: J O H N P E T E R S T E P H E N A R N O L D J A C K How should I go about sorting the array so that I end up with A R N O L D J A C K J O H N P E T E R S T E P H E N These is a 2d array of chars..... no strings or char points..... ...

C Programming: malloc() for a 2D array (using pointer-to-pointer)

Hi Guys, yesterday I had posted a question: How should I pass a pointer to a function and allocate memory for the passed pointer from inside the called function? From the answers I got, I was able to understand what mistake I was doing. I'm facing a new problem now, can anyone help out with this? I want to dynamically allocate a 2D ar...

Traverse 2D Array (Matrix) Diagonally

So I found this thread that was extremely helpful in traversing an array diagonally. I'm stuck though on mirroring it. For example: var m = 3; var n = 4; var a = new Array(); var b = 0; for(var i = 0; i < m; i++) { a[i] = new Array(n); for(var j = 0; j < n; j++) { a[i][j] = b; b++; } } for (var i = 0; i < m + n - 1; i+...

Sending 2 dim array using scatter

I am a beginner in MPI, and i am using C Language, and Simulator for Processors (MPICH2), i wrote the following code to send a 2D array to make 2 processors take a line from it but it produces error when running MPICH2, the code is: #include <stdio.h> #include <stdlib.h> #include "mpi.h" int main(int argc, char *argv[]) { int r...

How do i delete an empty array of objects?

Hello guys, i define an object: tempRes = new Object[100000][7]; now after that i fill it up till 100 rows for example. Now how to delete every object past that(from tempRes[100] too tempRes[10000]). I need this for a JTable. ...

How to use String arrays in 2D (String[][]) and to parse data in each space (specified element spot)?

I want to get a proxy list and parse it into an array of strings, txt is the proxy list, tmp[] is an array that has element in the form "ipaddr:port". ie. (tmp[] = {"i.p.i.p:port", "i.p.i.p:port", ...}). proxies array should be in 2d and look like this: {{"i.p.i.p","port"}, {"i.p.i.p","port"}, ...} but when running it java complains the ...

Finding the sum of 2D Arrays in Ruby

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...

What's going on here? Repeating rows in random list of lists.

I expected to get a grid of unique random numbers. Instead each row is the same sequence of numbers. What's going on here? from pprint import pprint from random import random nrows, ncols = 5, 5 grid = [[0] * ncols] * nrows for r in range(nrows): for c in range(ncols): grid[r][c] = int(random() * 100) pprint(grid) Examp...

How to manage 2d array in Smalltalk ?

I have a list of point and have to do erosion/dilation operations. I need a kind of 2d-array but can't find how to do in VisualWorks (I know there is a Array2d class in Squeak, but I must use VW). ...

Javascript 2D array issue - all elements are a copy of the final entry

Hi there, I'm creating a javascript 2D array from an XML file which I then manipulate and filter as necessary before displaying on the page. As I loop through the XML records, I manipulate the data a little, build a normal array from it (rowRecord) and then add this array to the 2D array (dataSet). Thing is, I end up with a nice 2D arr...