user88031
0
Q:

two dimensional array python

// Two-dimensional array.
int[,] array2D = new int[,] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
// The same array with dimensions specified.
int[,] array2Da = new int[4, 2] { { 1, 2 }, { 3, 4 }, { 5, 6 }, { 7, 8 } };
// A similar array with string elements.
string[,] array2Db = new string[3, 2] { { "one", "two" }, { "three", "four" },
                                        { "five", "six" } };

// Three-dimensional array.
int[, ,] array3D = new int[,,] { { { 1, 2, 3 }, { 4, 5, 6 } }, 
                                 { { 7, 8, 9 }, { 10, 11, 12 } } };
// The same array with dimensions specified.
int[, ,] array3Da = new int[2, 2, 3] 
{ { { 1, 2, 3 }, { 4, 5, 6 } },{ { 7, 8, 9 }, { 10, 11, 12 } } };
16
def build_matrix(rows, cols):
    matrix = []

    for r in range(0, rows):
        matrix.append([0 for c in range(0, cols)])

    return matrix

if __name__ == '__main__':
    build_matrix(6, 10)
5
from array import *

T = [[11, 12, 5, 2], [15, 6,10], [10, 8, 12, 5], [12,15,8,6]]
for r in T:
    for c in r:
        print(c,end = " ")
    print()
2
# Creates a list containing 5 lists, each of 8 items, all set to 0
w, h = 8, 5;
Matrix = [[0 for y in range(h)] for x in range(w)] 

Matrix[0][0] = 1
Matrix[0][6] = 3 # error! range... 
Matrix[6][0] = 3 # valid
0
for row in A:
    for val in row:
        print '{:4}'.format(val),
    print
0
//example of two dimensional array
var grid = [
  ["a", "b"],
  ["c", "d"],
  ["e", "f"]
];
console.log(grid[0][0]); // a
console.log(grid[1][1]); // d
console.log(grid);
2
# 5x6, 2-d array of booleans using list comprehension:

matrix = [[False for col in range(6)] for row in range(5)]

# 6x5, 2-d array of banana's using list comprehension:

matrix = [['banana' for col in range(5)] for row in range(6)]
0
using System;
using System.Collections.Generic;
using System.Linq;
public class Demo {
   public static void Main() {
      string[,] array = new string[3, 3];
      array[0, 0] = "One";
      array[0, 1] = "Two";
      array[0, 2] = "Three";
      array[1, 0] = "Four";
      array[1, 1] = "Five";
      array[1, 2] = "Six";
      array[2, 0] = "Seven";
      array[2, 1] = "Eight";
      array[2, 2] = "Nine";
      // getting upper bound
      int uBound0 = array.GetUpperBound(0);
      int uBound1 = array.GetUpperBound(1);
      for (int i = 0; i <= uBound0; i++) {
         for (int j = 0; j <= uBound1; j++) {
            string res = array[i, j];
            Console.WriteLine(res);
         }
      }
      Console.ReadLine();
   }
}
0
import numpy as np
print(np.matrix(A))
0

New to Communities?

Join the community