From: serialhex Date: 2011-01-08T11:46:42+09:00 Subject: Re: Nooby question : multidimensional arrays. --0016e64c1e766d9b6304994cbed1 Content-Type: text/plain; charset=ISO-8859-1 alright, so i've played around with it a bit more, and i kind of like your implementation... though if your trying to do what i think you are there are a few bugs in the implementation you should fix. from what i can see you want someone to be able to use a call like: dc[0,1] and get the second element of the second dimension of the data cube right? i think it's kinda cool, but the way it's currently implemented calling dc[3] does the same thing. in fact, check out this little irb session i just did: irb(main):100:0> dc = DataCube.new(1, 1) => [0] irb(main):101:0> dc[1,1]=1 => 1 irb(main):102:0> dc => [0, nil, nil, 1] irb(main):103:0> dc[1,0]=2 => 2 irb(main):104:0> dc => [0, 2, nil, 1] irb(main):105:0> dc[3]=7 => 7 irb(main):106:0> dc => [0, 2, nil, 7] i dont think that's the behavior you want. that aside, if you can get it working the way you want it to i think it'd be a pretty cool way to access everything. though how would i get all the elements in dimension 3? reading up on data cubes real quick one may want to do that... but overall it looks good and your implementation - though to my best knowledge unorthodox - will probably work fine if done right. hex (oh, and pizza rox sox!!) On Fri, Jan 7, 2011 at 8:27 PM, serialhex wrote: > Thanks for the feedback! > > > > np > > > > > I simply thought it would be nice if you can address elements simply as: > > A[i, j, k ...] > > > > true, it'd be nice but it kinda wont work... (see next) > > > > > > > uhm...i'm not sure what your trying to do with this, but what if i > > > wanted to > > > get the 5th element in the 4th dimension? > > > > Wouldn't that simply be dc[0,0,0,5]? > > > > no, that wont work. try your code in irb, with your 3x5 data cube... > > irb(main):055:0* dc = DataCube.new(3, 5) > => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0] > irb(main):056:0> dc[0,1,2]=44 > => 44 > irb(main):057:0> puts dc[0, 1, 2] > 44 > => nil > irb(main):058:0> puts dc.size > 125 > => nil > irb(main):059:0> dc > => [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 44, 0, > 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, > 0] > > thats the actual representation of the data cube in your computer. i'm not > sure that's exactly what you want, but it dosnt really look right to me. > > i dunno, mabye you are right and this is just a funky way to do this, i'll > take a longer look a little later, but now PIZZA!! > > hex > > > (yes, pizza is more important than you :P) > > > > > > > > > i'd write the generator method something like this: > > > > > > while i < @n > > > j = 0 > > > while j < @m > > > @array[[i]] << 0 > > > j += 1 > > > end > > > i += 1 > > > end > > > > > > (i havnt tested it, so it may not work) > > > > > > then you'd need to define the other accessor methods & such... but > > > thats a > > > start > > > > > > hex > > > > -- > > Posted via http://www.ruby-forum.com/. > > > > > --0016e64c1e766d9b6304994cbed1--