當前位置: 首頁>>代碼示例>>Python>>正文


Python numpy.rank方法代碼示例

本文整理匯總了Python中numpy.rank方法的典型用法代碼示例。如果您正苦於以下問題:Python numpy.rank方法的具體用法?Python numpy.rank怎麽用?Python numpy.rank使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在numpy的用法示例。


在下文中一共展示了numpy.rank方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rank [as 別名]
def __init__(self, config, rng=None):
    self.rng = np.random.RandomState(1) if rng is None else rng

    self.data_path = os.path.join(config.data_dir, 'gaze')
    self.sample_path = os.path.join(self.data_path, config.sample_dir)
    self.batch_size = config.batch_size
    self.debug = config.debug

    self.real_data, synthetic_image_path = load(config, self.data_path, self.sample_path, rng)

    self.synthetic_data_paths = np.array(glob(os.path.join(synthetic_image_path, '*_cropped.png')))
    self.synthetic_data_dims = list(imread(self.synthetic_data_paths[0]).shape) + [1]

    self.synthetic_data_paths.sort()

    if np.rank(self.real_data) == 3:
      self.real_data = np.expand_dims(self.real_data, -1)
    
    self.real_p = 0 
開發者ID:carpedm20,項目名稱:simulated-unsupervised-tensorflow,代碼行數:21,代碼來源:gaze_data.py

示例2: test

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rank [as 別名]
def test(self):
        a = np.arange(10)
        assert_warns(np.VisibleDeprecationWarning, np.rank, a) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:5,代碼來源:test_deprecations.py

示例3: matrixRank

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rank [as 別名]
def matrixRank(arr, tol=1e-8):
    """
    Computes the rank of an array/matrix, i.e. number of linearly independent
    variables. This is not the same as numpy.rank() which only returns the
    number of ways (2-way, 3-way, etc) an array/matrix has.

    PARAMETERS
    ----------
    arrX : numpy array
        A numpy array containing the data

    RETURNS
    -------
    scalar
        Rank of matrix.

    Examples
    --------
    >>> import hoggorm as ho
    >>>
    >>> # Get the rank of the data
    >>> ho.matrixRank(myData)
    >>> 8

    """
    if len(arr.shape) != 2:
        raise ValueError('Input must be a 2-d array or Matrix object')

    s = numpy.linalg.svd(arr, compute_uv=0)
    return numpy.sum(numpy.where(s > tol, 1, 0)) 
開發者ID:olivertomic,項目名稱:hoggorm,代碼行數:32,代碼來源:statTools.py

示例4: scalfact2

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rank [as 別名]
def scalfact2(ex,ey,ed,rat=0.2):
    """
    Determine scale factor for drawing computational results, such as 
    displacements, section forces or flux.
    
    Parameters:
    
        ex, ey      element node coordinates
                       
        ed          element displacement matrix or section force matrix
    
        rat         relation between illustrated quantity and element size. 
                    If not specified, 0.2 is used.
        
    """

    nen = -1
    if ex.shape != ey.shape:
        print("ex and ey shapes do not match.")
        return 1.0
    
    dlmax = 0.
    edmax = 1.
    
    if np.rank(ex)==1:
        nen = ex.shape[0]
        nel = 1
        dxmax=ex.T.max()-ex.T.min()
        dymax=ey.T.max()-ey.T.min()
        dlmax=max(dxmax,dymax);
        edmax=abs(ed).max();
    else:
        nen = ex.shape[1]
        nel = ex.shape[0]
        dxmax=ex.T.max()-ex.T.min()
        dymax=ey.T.max()-ey.T.min()
        dlmax=max(dxmax,dymax);
        edmax=abs(ed).max();
        
    k = rat
    return k*dlmax/edmax 
開發者ID:CALFEM,項目名稱:calfem-python,代碼行數:43,代碼來源:utils.py

示例5: getnnz

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rank [as 別名]
def getnnz(self):
        nnz = len(self.data)
        if nnz != len(self.row) or nnz != len(self.col):
            raise ValueError('row, column, and data array must all be the same length')

        if np.rank(self.data) != 1 or np.rank(self.row) != 1 or np.rank(self.col) != 1:
            raise ValueError('row, column, and data arrays must have rank 1')

        return int(nnz) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:11,代碼來源:coo.py

示例6: isshape

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rank [as 別名]
def isshape(x):
    """Is x a valid 2-tuple of dimensions?
    """
    try:
        # Assume it's a tuple of matrix dimensions (M, N)
        (M, N) = x
    except:
        return False
    else:
        if isintlike(M) and isintlike(N):
            if np.rank(M) == 0 and np.rank(N) == 0:
                return True
        return False 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:15,代碼來源:sputils.py

示例7: var_regression_matrix

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rank [as 別名]
def var_regression_matrix(H, x, model, sigma=1):
    """
    Compute the variance of the 'regression error'.
    
    Parameters
    ----------
    H : 2d-array
        The regression matrix
    x : 2d-array
        The coordinates to calculate the regression error variance at.
    model : str
        A string of tokens that define the regression model (e.g. 
        '1 x1 x2 x1*x2')
    sigma : scalar
        An estimate of the variance (default: 1).
    
    Returns
    -------
    var : scalar
        The variance of the regression error, evaluated at ``x``.
        
    """
    x = np.atleast_2d(x)
    H = np.atleast_2d(H)
    
    if x.shape[0]==1:
        x = x.T
    
    if np.rank(H)<(np.dot(H.T, H)).shape[0]:
        raise ValueError("model and DOE don't suit together")
    
    x_mod = build_regression_matrix(x, model)
    var = sigma**2*np.dot(np.dot(x_mod.T, np.linalg.inv(np.dot(H.T, H))), x_mod)
    return var 
開發者ID:franciscovillaescusa,項目名稱:Quijote-simulations,代碼行數:36,代碼來源:var_regression_matrix.py

示例8: test_lstsq

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rank [as 別名]
def test_lstsq(self):
        b = np.array([1., 2., 4.]) * u.m / u.s
        x, residuals, rank, s = np.linalg.lstsq(self.q, b, rcond=None)
        xx, residualsx, rankx, sx = np.linalg.lstsq(self.q.value, b.value,
                                                    rcond=None)
        xx <<= b.unit / self.q.unit
        residualsx <<= b.unit ** 2
        sx <<= self.q.unit

        assert_array_equal(x, xx)
        assert_array_equal(residuals, residualsx)
        assert_array_equal(s, sx)
        assert rank == rankx
        assert u.allclose(self.q @ x, b)

        # Also do one where we can check the answer...
        m = np.eye(3)
        b = np.arange(3) * u.m
        x, residuals, rank, s = np.linalg.lstsq(m, b, rcond=1.*u.percent)
        assert_array_equal(x, b)
        assert np.all(residuals == 0 * u.m**2)
        assert rank == 3
        assert_array_equal(s, np.array([1., 1., 1.]) << u.one)

        with pytest.raises(u.UnitsError):
            np.linalg.lstsq(m, b, rcond=1.*u.s) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:28,代碼來源:test_quantity_non_ufuncs.py

示例9: rank

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rank [as 別名]
def rank(a):
    """
    Return the number of dimensions of an array.

    If `a` is not already an array, a conversion is attempted.
    Scalars are zero dimensional.

    .. note::
        This function is deprecated in NumPy 1.9 to avoid confusion with
        `numpy.linalg.matrix_rank`. The ``ndim`` attribute or function
        should be used instead.

    Parameters
    ----------
    a : array_like
        Array whose number of dimensions is desired. If `a` is not an array,
        a conversion is attempted.

    Returns
    -------
    number_of_dimensions : int
        The number of dimensions in the array.

    See Also
    --------
    ndim : equivalent function
    ndarray.ndim : equivalent property
    shape : dimensions of array
    ndarray.shape : dimensions of array

    Notes
    -----
    In the old Numeric package, `rank` was the term used for the number of
    dimensions, but in Numpy `ndim` is used instead.

    Examples
    --------
    >>> np.rank([1,2,3])
    1
    >>> np.rank(np.array([[1,2,3],[4,5,6]]))
    2
    >>> np.rank(1)
    0

    """
    # 2014-04-12, 1.9
    warnings.warn(
        "`rank` is deprecated; use the `ndim` attribute or function instead. "
        "To find the rank of a matrix see `numpy.linalg.matrix_rank`.",
        VisibleDeprecationWarning)
    try:
        return a.ndim
    except AttributeError:
        return asarray(a).ndim 
開發者ID:abhisuri97,項目名稱:auto-alt-text-lambda-api,代碼行數:56,代碼來源:fromnumeric.py

示例10: rank

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rank [as 別名]
def rank(a):
    """
    Return the number of dimensions of an array.

    If `a` is not already an array, a conversion is attempted.
    Scalars are zero dimensional.

    .. note::
        This function is deprecated in NumPy 1.9 to avoid confusion with
        `numpy.linalg.matrix_rank`. The ``ndim`` attribute or function
        should be used instead.

    Parameters
    ----------
    a : array_like
        Array whose number of dimensions is desired. If `a` is not an array,
        a conversion is attempted.

    Returns
    -------
    number_of_dimensions : int
        The number of dimensions in the array.

    See Also
    --------
    ndim : equivalent function
    ndarray.ndim : equivalent property
    shape : dimensions of array
    ndarray.shape : dimensions of array

    Notes
    -----
    In the old Numeric package, `rank` was the term used for the number of
    dimensions, but in NumPy `ndim` is used instead.

    Examples
    --------
    >>> np.rank([1,2,3])
    1
    >>> np.rank(np.array([[1,2,3],[4,5,6]]))
    2
    >>> np.rank(1)
    0

    """
    # 2014-04-12, 1.9
    warnings.warn(
        "`rank` is deprecated; use the `ndim` attribute or function instead. "
        "To find the rank of a matrix see `numpy.linalg.matrix_rank`.",
        VisibleDeprecationWarning, stacklevel=2)
    try:
        return a.ndim
    except AttributeError:
        return asarray(a).ndim 
開發者ID:birforce,項目名稱:vnpy_crypto,代碼行數:56,代碼來源:fromnumeric.py

示例11: check_format

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import rank [as 別名]
def check_format(self, full_check=True):
        """check whether the matrix format is valid

            *Parameters*:
                full_check:
                    True  - rigorous check, O(N) operations : default
                    False - basic check, O(1) operations

        """
        M,N = self.shape
        R,C = self.blocksize

        # index arrays should have integer data types
        if self.indptr.dtype.kind != 'i':
            warn("indptr array has non-integer dtype (%s)"
                    % self.indptr.dtype.name)
        if self.indices.dtype.kind != 'i':
            warn("indices array has non-integer dtype (%s)"
                    % self.indices.dtype.name)

        # only support 32-bit ints for now
        self.indptr = np.asarray(self.indptr, np.intc)
        self.indices = np.asarray(self.indices, np.intc)
        self.data = to_native(self.data)

        # check array shapes
        if np.rank(self.indices) != 1 or np.rank(self.indptr) != 1:
            raise ValueError("indices, and indptr should be rank 1")
        if np.rank(self.data) != 3:
            raise ValueError("data should be rank 3")

        # check index pointer
        if (len(self.indptr) != M//R + 1):
            raise ValueError("index pointer size (%d) should be (%d)" %
                                (len(self.indptr), M//R + 1))
        if (self.indptr[0] != 0):
            raise ValueError("index pointer should start with 0")

        # check index and data arrays
        if (len(self.indices) != len(self.data)):
            raise ValueError("indices and data should have the same size")
        if (self.indptr[-1] > len(self.indices)):
            raise ValueError("Last value of index pointer should be less than "
                                "the size of index and data arrays")

        self.prune()

        if full_check:
            # check format validity (more expensive)
            if self.nnz > 0:
                if self.indices.max() >= N//C:
                    raise ValueError("column index values must be < %d (now max %d)" % (N//C, self.indices.max()))
                if self.indices.min() < 0:
                    raise ValueError("column index values must be >= 0")
                if np.diff(self.indptr).min() < 0:
                    raise ValueError("index pointer values must form a "
                                        "non-decreasing sequence")

        # if not self.has_sorted_indices():
        #    warn('Indices were not in sorted order. Sorting indices.')
        #    self.sort_indices(check_first=False) 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:63,代碼來源:bsr.py


注:本文中的numpy.rank方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。