From: Robert Klemme Date: 2009-09-04T19:59:58+09:00 Subject: Re: Array.transpose on [[]] or [[],[]] 2009/9/4 Ralf Mueller : > Sebastian Hungerecker wrote: >> >> Ralf Mueller wrote: >> >>> >>> I wondered why [[]].transpose = [] and [[],[]].transpose = [] >>> I expected them to be [[]], because the result would still be an array >>> of arrays. >>> >> >> You can think of [] as an array of 0 arrays in this case. >> The number of arrays in the array returned by transpose equals the number >> of items in each subarray of the original array. So if that number is 0, >> it >> makes sense that the returned array would also have 0 subarrays. > sure, but [[]] has a subarray. so, shouldn't [[]].transpose have one too? To > point it out in a more general way: I thought, if 'transpose' can be applied > to an array, it should behave like an involution: a.transpose.transpose = a. > > anyway, one more thing to remember... No, [[]].transpose should not have a sub array: [[]] must be seen as a matrix with one row with no columns. If you transpose it you get a matrix with no row with one column hence []. It does not matter when you exchange terms "row" and "columns" in the sentence above. Personally I would be using a specialized Matrix class anyway if you need to work with matrices. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/