Esempio n. 1
0
def arange(start, stop=None, step=1, dtype=None):
    """arange([start,] stop[, step=1])
    
    Return evenly spaced values within a given interval.
    
    Values are generated within the half-open interval ``[start, stop)``
    (in value words, the interval including `start` but excluding `stop`).
    
    Parameters
    ----------
    start : number, optional
        Start of interval.  The interval includes this value.  The default
        start value is 0.
    stop : number
        End of interval.  The interval does not include this value.
    step : number, optional
        Spacing between values.  For any output `out`, this is the distance
        between two adjacent values, ``out[i+1] - out[i]``.  The default
        step size is 1.  If `step` is specified, `start` must also be given.
        
    Examples:
    
    arange(5)
    arange(1, 5, 0.5)
    """
    if stop is None:
        # Only one number given, which is the 'stop'
        stop = start
        start = 0
    if dtype is None:
        return ndarray(NDMatrix.arange(start, stop, step))
    else:
        return ndarray(NDMatrix.arange(start, stop, step, dtype))
Esempio n. 2
0
def arange(start, stop=None, step=1, dtype=None):
    """arange([start,] stop[, step=1])
    
    Return evenly spaced values within a given interval.
    
    Values are generated within the half-open interval ``[start, stop)``
    (in value words, the interval including `start` but excluding `stop`).
    
    Parameters
    ----------
    start : number, optional
        Start of interval.  The interval includes this value.  The default
        start value is 0.
    stop : number
        End of interval.  The interval does not include this value.
    step : number, optional
        Spacing between values.  For any output `out`, this is the distance
        between two adjacent values, ``out[i+1] - out[i]``.  The default
        step size is 1.  If `step` is specified, `start` must also be given.
        
    Examples:
    
    arange(5)
    arange(1, 5, 0.5)
    """
    if stop is None:
        # Only one number given, which is the 'stop'
        stop = start
        start = 0
    if dtype is None:
        return ndarray(NDMatrix.arange(start, stop, step))
    else:
        return ndarray(NDMatrix.arange(start, stop, step, dtype))
Esempio n. 3
0
def dot(a, b):
    """dot(a, b):
       Determine matrix 'dot' product of arrays a and b
    """
    result = ndarray(NDMatrix.dot(a.nda, b.nda))
    if result.ndim == 1 and len(result) == 1:
        return result[0]
    return result
Esempio n. 4
0
def linspace(start, stop, num=50, dtype=float):
    """linspace(start, stop, num=50, dtype=float)
    
    Return evenly spaced values from start to stop, including stop.
    Example:
    linspace(2, 10, 5)
    """
    return ndarray(NDMatrix.linspace(start, stop, num, dtype))
Esempio n. 5
0
def zeros(shape, dtype=float):
    """zeros(shape, dtype=float)
    
    Create array of zeros, example:
    
    zeros( (2, 3) )
    """
    return ndarray(NDMatrix.zeros(dtype, __toNDShape__(shape)))
Esempio n. 6
0
def ones(shape, dtype=float):
    """ones(shape, dtype=float)
    
    Create array of ones, example:
    
    ones( (2, 3) )
    """
    return ndarray(NDMatrix.ones(dtype, __toNDShape__(shape)))
Esempio n. 7
0
def dot(a, b):
    """dot(a, b):
       Determine matrix 'dot' product of arrays a and b
    """
    result = ndarray(NDMatrix.dot(a.nda, b.nda))
    if result.ndim == 1 and len(result) == 1:
        return result[0]
    return result
Esempio n. 8
0
def linspace(start, stop, num=50, dtype=float):
    """linspace(start, stop, num=50, dtype=float)
    
    Return evenly spaced values from start to stop, including stop.
    Example:
    linspace(2, 10, 5)
    """
    return ndarray(NDMatrix.linspace(start, stop, num, dtype))
Esempio n. 9
0
def ones(shape, dtype=float):
    """ones(shape, dtype=float)
    
    Create array of ones, example:
    
    ones( (2, 3) )
    """
    return ndarray(NDMatrix.ones(dtype, __toNDShape__(shape)))
Esempio n. 10
0
def zeros(shape, dtype=float):
    """zeros(shape, dtype=float)
    
    Create array of zeros, example:
    
    zeros( (2, 3) )
    """
    return ndarray(NDMatrix.zeros(dtype, __toNDShape__(shape)))
Esempio n. 11
0
def transpose(a, axes=None):
    """transpose(a, axes=None):
       Permute the axes of an array.
       By default, they are reversed.
       In a 2D array this would swap 'rows' and 'columns'
    """
    if axes is None:
        return a.transpose()
    return ndarray(NDMatrix.transpose(a.nda, axes))
Esempio n. 12
0
def reshape(a, shape):
    """reshape(array, shape):
    Create array view with new shape
    
    Example:
    reshape(arange(6), (3, 2))
    results in array([ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ] ])
    """
    return ndarray(NDMatrix.reshape(self.nda, __toNDShape__(shape)))
Esempio n. 13
0
def transpose(a, axes=None):
    """transpose(a, axes=None):
       Permute the axes of an array.
       By default, they are reversed.
       In a 2D array this would swap 'rows' and 'columns'
    """
    if axes is None:
        return a.transpose()
    return ndarray(NDMatrix.transpose(a.nda, axes))
Esempio n. 14
0
def reshape(a, shape):
    """reshape(array, shape):
    Create array view with new shape
    
    Example:
    reshape(arange(6), (3, 2))
    results in array([ [ 0, 1 ], [ 2, 3 ], [ 4, 5 ] ])
    """
    return ndarray(NDMatrix.reshape(self.nda, __toNDShape__(shape)))
Esempio n. 15
0
 def transpose(self):
     """Compute transposed array, i.e. swap 'rows' and 'columns'"""
     return ndarray(NDMatrix.transpose(self.nda))
Esempio n. 16
0
 def transpose(self):
     """Compute transposed array, i.e. swap 'rows' and 'columns'"""
     return ndarray(NDMatrix.transpose(self.nda))