Array construction from a Python list

  • array(list, [datatype]) generates an array from a list:
    >>> pl = [0, 1.2, 4, -9.1, 5, 8] 
    >>> a = array(pl)
    
    The array elements are of the simplest possible type:
    >>> z = array([1, 2, 3])
    >>> print z                     # array of integers
    [1 2 3]                                         
    >>> z = array([1, 2, 3], float)
    >>> print z
    [ 1.  2.  3.]
    
    A two-dim. array from two one-dim. lists:
    >>> x = [0, 0.5, 1]; y = [-6.1, -2, 1.2]  # Python lists
    >>> a = array([x, y])  # form array with x and y as rows
    
    From array to list: alist = a.tolist()

    previousnexttable of contents