> <[EMAIL PROTECTED]> wrote: > > > On Jun 17, 8:29 am, goric <[EMAIL PROTECTED]> wrote: > >> Hello, > >> I need some methods that permit to add a line or a column in a matrix > >> in that way: > > >> M = Matrix(3,3,lambda i,j: i+j) > >> M > >> ⎡0 1 2⎤ > >> ⎢1 2 3⎥ > >> ⎣2 3 4⎦ > >> V = Matrix(3,1,lambda i,j: 3+i+j) > >> V > >> ⎡3⎤ > >> ⎢4⎥ > >> ⎣5⎦ > >> M.append_col(V) > >> M > >> ⎡0 1 2 3⎤ > >> ⎢1 2 3 4⎥ > >> ⎣2 3 4 5⎦ > >> VL = [3,4,5,6] > >> M.append_line(VL) > >> M > >> ⎡0 1 2 3⎤ > >> ⎢1 2 3 4⎥ > >> ⎢2 3 4 5⎥ > >> ⎣3 4 5 6⎦ > > >> Can I implement them? The names I gave to them are good or do you > >> suggest any other name? I'll wait your opinion to start working. > > > I'd suggest using names: > > insert_row, insert_column, append_row, append_column > > > where insert_row(index, row) etc. > > > Another option is to have something similar to numpy > > > insert(index, seq, axis=None) > > append(seq, axis=None) > > > See numpy.insert and numpy.append functions for more info. > > Thta's ok with me too. We can even have both. > > Ondrej
Considering numpy API I think that numpy.vstack() numpy.hstack() are more similar to append_row, append_column because numpy.append does ravel the array if you call as: append( M, V ) But implementing also insert and append that works like numpy is a good idea. I think the best way is to implement with the maximum API compatibility with numpy in that way: M = Matrix(3,3,lambda i,j: i+j) M ⎡0 1 2⎤ ⎢1 2 3⎥ ⎣2 3 4⎦ V = Matrix(3,1,lambda i,j: 3+i+j) V ⎡3⎤ ⎢4⎥ ⎣5⎦ hstack(M,V) ⎡0 1 2 3⎤ ⎢1 2 3 4⎥ ⎣2 3 4 5⎦ M.append_column(V) M ⎡0 1 2 3⎤ ⎢1 2 3 4⎥ ⎣2 3 4 5⎦ VL = [3,4,5,6] vstack(VL) ⎡0 1 2 3⎤ ⎢1 2 3 4⎥ ⎢2 3 4 5⎥ ⎣3 4 5 6⎦ M.append_row(VL) M ⎡0 1 2 3⎤ ⎢1 2 3 4⎥ ⎢2 3 4 5⎥ ⎣3 4 5 6⎦ What do you think? Riccardo --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sympy" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sympy?hl=en -~----------~----~----~----~------~----~------~--~---
