Ruby - 2D array column to 1D array

Rofellos's Avatar, Join Date: Dec 2010
Light Poster
Hello,

Is there any method to do this without using a loop to collect the values?


Ex.:
2D array: array =
[1] [11] [21] [31] [41]
[2] [12] [22] [32] [42]
[3] [13] [23] [33] [43]
[4] [14] [24] [34] [44]
[5] [15] [25] [35] [45]
[6] [16] [26] [36] [46]
[7] [17] [27] [37] [47]
[8] [18] [28] [38] [48]
[9] [19] [29] [39] [49]
[10] [20] [30] [40] [50]

To get the second row, it can be done like this array[1]
return 1D array: [2] [12] [22] [32] [42]

Is there something like this to get columns?
0
Rofellos's Avatar, Join Date: Dec 2010
Light Poster
Solved:

To get the first row:
a[0]

To get the first column:
a.transpose[0]
shabbir like this