digitalmars.D.learn - select all rows (resp. columns) out of matrix
- seany (7/7) Nov 14 2013 How do I access All rows (resp. columns ) of a Matrix /
- TheFlyingFiddle (13/20) Nov 14 2013 unittest
- TheFlyingFiddle (8/25) Nov 14 2013 Sry the way you get rows is wrong.
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (4/25) Nov 14 2013 transversal() is useful too: :)
- TheFlyingFiddle (2/5) Nov 14 2013 Did not know about this one. Thanks for pointing it out :D
- bearophile (10/12) Nov 14 2013 transversal() is sometimes useful, but if you need a significant
- H. S. Teoh (9/22) Nov 14 2013 [...]
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] ?
Nov 14 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]; } }
Nov 14 2013
On Thursday, 14 November 2013 at 22:18:44 UTC, TheFlyingFiddle wrote: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]; } }Sry the way you get rows is wrong. It should be int[] row0; foreach(collumn; matrix) row0 ~= collumn[0]; and notint[] row0; //Loop over all collumns foreach(i; matrix) { row0 ~= matrix[i][0]; }
Nov 14 2013
On 11/14/2013 02:18 PM, TheFlyingFiddle wrote:On Thursday, 14 November 2013 at 22:06:28 UTC, seany wrote:transversal() is useful too: :) http://dlang.org/phobos/std_range.html#transversal AliHow 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]; } }
Nov 14 2013
On Thursday, 14 November 2013 at 22:26:03 UTC, Ali Çehreli wrote:transversal() is useful too: :) http://dlang.org/phobos/std_range.html#transversal AliDid not know about this one. Thanks for pointing it out :D
Nov 14 2013
Ali Çehreli:transversal() is useful too: :) http://dlang.org/phobos/std_range.html#transversaltransversal() is sometimes useful, but if you need a significant amount of matrix processing, slicing and dicing matrices all the time in scientific code, then probably it's better to use a custom matrix library for D. Eventually one "winner" of such libraries should come out for D (as NumPy is in Python world). But to implement such libraries D should improve its management of "$" and "..." more for user-defined types. Bye, bearophile
Nov 14 2013
On Fri, Nov 15, 2013 at 12:13:11AM +0100, bearophile wrote:Ali Çehreli:[...] '$' already works for multidimensional arrays, you just have to implement opDollar appropriately. Slicing syntax isn't, though. Kenji has a pull for it, but it hasn't been merged yet for whatever reason. T -- Once bitten, twice cry...transversal() is useful too: :) http://dlang.org/phobos/std_range.html#transversaltransversal() is sometimes useful, but if you need a significant amount of matrix processing, slicing and dicing matrices all the time in scientific code, then probably it's better to use a custom matrix library for D. Eventually one "winner" of such libraries should come out for D (as NumPy is in Python world). But to implement such libraries D should improve its management of "$" and "..." more for user-defined types.
Nov 14 2013