select all rows (resp. columns) out of matrix
TheFlyingFiddle
theflyingfiddle at gmail.com
Thu Nov 14 14:18:42 PST 2013
On Thursday, 14 November 2013 at 22:06:28 UTC, seany wrote:
> How do I access All rows (resp. columns ) of a Matrix /
> multidimensional array?
>
> In scilab, you write array_var(:,row_index), colon meaning all
> columns, at that particular row given by row index will be
> selected.
>
> can you, forexample, in D, write, array_var[0][] to select all
> elements (columns, in this case i believe?) of array_var[0] ?
unittest
{
int[][] matrix = new int[][](n,m);
//Getting a collumn is simple.
int[] collumn0 = matrix[0];
//Getting a row is trickier
int[] row0;
//Loop over all collumns
foreach(i; matrix) {
row0 ~= matrix[i][0];
}
}
More information about the Digitalmars-d-learn
mailing list