How to add columns to python arrays

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • CC

    #1

    How to add columns to python arrays

    Hi there,

    I wanna compile a 6000x1000 array with python. The array starts from
    'empty', each time I get a 6000 length list, I wanna add it to the
    exist array as a column vector. Is there any function to do so?

    Or, I can add the list as a rows, if this is easier, and transpose the
    whole array after all the rows are setup.

    Thanks so much.

  • Terry Reedy

    #2
    Re: How to add columns to python arrays


    "CC" <chuangwoo@gmai l.com> wrote in message
    news:1147882432 .166728.207820@ j55g2000cwa.goo glegroups.com.. .[color=blue]
    > I wanna compile a 6000x1000 array with python. The array starts from
    > 'empty', each time I get a 6000 length list, I wanna add it to the
    > exist array as a column vector. Is there any function to do so?
    >
    > Or, I can add the list as a rows, if this is easier, and transpose the
    > whole array after all the rows are setup.[/color]

    Python does not come with a 2D array type either as a builtin type or as a
    standard library module. You can only simulate one with a sequence of
    sequences (list of lists, for instance). You could initialize as follows:

    aray = []
    for l6000 in source(): aray.append(l60 00)

    While this will print as a list of rows, you are free to think of it as a
    list of columns.

    That said, I suspect you should use the 3rd party NumPy package which
    defines multiple-dimensional arrays of several base types.

    Terry Jan Reedy



    Comment

    • Michael Spencer

      #3
      Re: How to add columns to python arrays

      Terry Reedy wrote:[color=blue]
      > "CC" <chuangwoo@gmai l.com> wrote in message
      > news:1147882432 .166728.207820@ j55g2000cwa.goo glegroups.com.. .[color=green]
      >> I wanna compile a 6000x1000 array with python. The array starts from
      >> 'empty', each time I get a 6000 length list, I wanna add it to the
      >> exist array as a column vector. Is there any function to do so?
      >>
      >> Or, I can add the list as a rows, if this is easier, and transpose the
      >> whole array after all the rows are setup.[/color]
      >
      > Python does not come with a 2D array type either as a builtin type or as a
      > standard library module. You can only simulate one with a sequence of
      > sequences (list of lists, for instance). You could initialize as follows:
      >
      > aray = []
      > for l6000 in source(): aray.append(l60 00)
      >
      > While this will print as a list of rows, you are free to think of it as a
      > list of columns.
      >
      > That said, I suspect you should use the 3rd party NumPy package which
      > defines multiple-dimensional arrays of several base types.
      >
      > Terry Jan Reedy
      >
      >
      >[/color]
      If you're just looking for a multi-dimensional array type, and don't need
      maximum speed or the vast range of array-processing that numpy offers, then
      *pyarray* provides a pure-python single module solution.

      the latest pyarray is available with tests and documentation at:


      Introduction
      ============
      pyarray is a pure-Python implementation of a multi-dimensional array type.

      pyarray.ListVie w and pyarray.ArrayVi ew offer a substantial subset of
      numpy.ArrayType functionality, by wrapping standard python 'list' and
      'array.array' respectively.

      Key features include:
      * Views: all subscripting operations apart from individual cell access
      access return views to existing 'live' data
      * Extended Indexing: slicing, arbitrary 'takes', index arrays etc...
      * Unlimited re-shaping: while still addressing one data-source
      * Elementwise binary operations: all basic arithmetic and comparison
      operations
      * Data broadcasting: allows assignment and binary operations between
      views of different shapes
      * Friendly __repr__: work safely with big arrays at the interactive prompt

      Regards
      Michael


      Comment

      • Terry Reedy

        #4
        Re: How to add columns to python arrays


        "Michael Spencer" <mahs@telcopart ners.com> wrote in message
        news:e4ft0l$356 $1@sea.gmane.or g...[color=blue]
        > If you're just looking for a multi-dimensional array type, and don't need
        > maximum speed or the vast range of array-processing that numpy offers,
        > then
        > *pyarray* provides a pure-python single module solution.
        >
        > the latest pyarray is available with tests and documentation at:
        > http://svn.brownspencer.com/pyarray/trunk/[/color]

        Nice. I downloaded and expect to give it a try sometime. I suggest
        putting the url in the module file itself to make it easier to search for
        updated versions ;-)

        tjr



        Comment

        • Michael Spencer

          #5
          Re: How to add columns to python arrays

          Terry Reedy wrote:[color=blue]
          > "Michael Spencer" <mahs@telcopart ners.com> wrote in message
          > news:e4ft0l$356 $1@sea.gmane.or g...[color=green]
          >> If you're just looking for a multi-dimensional array type, and don't need
          >> maximum speed or the vast range of array-processing that numpy offers,
          >> then
          >> *pyarray* provides a pure-python single module solution.
          >>
          >> the latest pyarray is available with tests and documentation at:
          >> http://svn.brownspencer.com/pyarray/trunk/[/color]
          >
          > Nice. I downloaded and expect to give it a try sometime. I suggest
          > putting the url in the module file itself to make it easier to search for
          > updated versions ;-)
          >
          > tjr
          >
          >
          >[/color]
          Thanks for the suggestion, Terry. I've added a static link in each source file
          to the repository at: http://svn.brownspencer.com/pyarray/
          and also added an email address. If you do try it, I'd be interested to hear
          your feedback.

          Michael

          Comment

          Working...