two simple questions about arrays

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jenya56
    New Member
    • Nov 2009
    • 14

    two simple questions about arrays

    Dear all:
    1.) how to initilize numpy array? I need something similar to:
    data = []
    2.) how to add elements to nested lists?
    I have list a:
    a= [[1 2][1 2 3 3]]
    how to append something to a[0]
    THANKS SO MUCH.
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Code:
    >>> numpy.zeros(10)
    array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])
    >>> a= [[1, 2],[1, 2, 3, 3]]
    >>> a[0].append('something')
    >>> a
    [[1, 2, 'something'], [1, 2, 3, 3]]
    >>>

    Comment

    • jenya56
      New Member
      • Nov 2009
      • 14

      #3
      but here you assume you know the size of your array

      I do not know the size....

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        OK, then how about:
        Code:
        >>> numpy.zeros(0)
        array([], dtype=float64)
        >>>

        Comment

        • jenya56
          New Member
          • Nov 2009
          • 14

          #5
          THANK YOU so much....

          Comment

          • jenya56
            New Member
            • Nov 2009
            • 14

            #6
            Hi, I was wondering if you could help me again....How do I add something to numpy array? Say I have :
            >>> a= numpy.zeros(0)
            Then I want to start adding elements to a. By the end I want a to look something like this a=[[1, 2], [4]]. I have no problem doing it with the actual python lists.

            Comment

            • bvdet
              Recognized Expert Specialist
              • Oct 2006
              • 2851

              #7
              Perhaps you should read the numpy documentation.

              Comment

              Working...