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


Python numpy.array_equiv方法代碼示例

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


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

示例1: test_fix_array_len

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def test_fix_array_len():
    from jesse.store.state_orderbook import _fix_array_len

    a = np.array([
        1, 2, 3, 4, 5
    ], dtype=float)

    a = _fix_array_len(a, 7)
    b = np.array([
        1, 2, 3, 4, 5
    ], dtype=float)

    assert np.array_equiv(a[:5], b)
    assert np.isnan(a[5])
    assert np.isnan(a[6])

    c = np.array([
        1, 2, 3, 4, 5
    ], dtype=float)

    # assert that len has to be >= len(a)
    with pytest.raises(ValueError):
        _fix_array_len(c, 3) 
開發者ID:jesse-ai,項目名稱:jesse,代碼行數:25,代碼來源:test_state_orderbook.py

示例2: equiv

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def equiv(self, other):
        """Return True if other is an equivalent weighting.

        Returns
        -------
        equivalent : bool
            ``True`` if ``other`` is a `Weighting` instance with the same
            `Weighting.impl`, which yields the same result as this
            weighting for any input, ``False`` otherwise. This is checked
            by entry-wise comparison of arrays/constants.
        """
        # Optimization for equality
        if self == other:
            return True
        elif (not isinstance(other, Weighting) or
              self.exponent != other.exponent):
            return False
        elif isinstance(other, MatrixWeighting):
            return other.equiv(self)
        elif isinstance(other, ConstWeighting):
            return np.array_equiv(self.array, other.const)
        else:
            return np.array_equal(self.array, other.array) 
開發者ID:odlgroup,項目名稱:odl,代碼行數:25,代碼來源:weighting.py

示例3: check_numpy_array

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def check_numpy_array(feature, array, n_mentions_list, compressed=True):
    for n_mentions in n_mentions_list:
        if feature == FEATURES_NAMES[0]:
            assert array.shape[0] == len(n_mentions)
            if compressed:
                assert np.array_equiv(
                    array[:, 3], np.array([len(n_mentions)] * len(n_mentions))
                )
                assert np.max(array[:, 2]) == len(n_mentions) - 1
                assert np.min(array[:, 2]) == 0
        elif feature == FEATURES_NAMES[1]:
            assert array.shape[0] == len(n_mentions)
        elif feature == FEATURES_NAMES[2]:
            assert array.shape[0] == len(n_mentions)
            assert np.array_equiv(array[:, 0], np.array(list(range(len(n_mentions)))))
        elif feature == FEATURES_NAMES[3]:
            assert array.shape[0] == len(n_mentions)
            assert np.array_equiv(
                array[:, 0], np.array([p * (p - 1) / 2 for p in range(len(n_mentions))])
            )
        elif feature == FEATURES_NAMES[4]:
            assert array.shape[0] == len(n_mentions)
        elif feature == FEATURES_NAMES[5]:
            assert array.shape[0] == len(n_mentions)
        elif feature == FEATURES_NAMES[6]:
            assert array.shape[0] == len(n_mentions) * (len(n_mentions) - 1) / 2
            assert np.max(array) == len(n_mentions) - 2
        elif feature == FEATURES_NAMES[7]:
            if compressed:
                assert array.shape[0] == len(n_mentions) * (len(n_mentions) - 1) / 2
                assert np.max(array[:, 7]) == len(n_mentions) - 2
                assert np.min(array[:, 7]) == 0
        elif feature == FEATURES_NAMES[8]:
            assert array.shape[0] == len(n_mentions) * (len(n_mentions) - 1) / 2


###############################################################################################
### PARALLEL FCT (has to be at top-level of the module to be pickled for multiprocessing) ##### 
開發者ID:huggingface,項目名稱:neuralcoref,代碼行數:40,代碼來源:conllparser.py

示例4: array_equal

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def array_equal(a1, a2):
    """
    True if two arrays have the same shape and elements, False otherwise.

    Parameters
    ----------
    a1, a2 : array_like
        Input arrays.

    Returns
    -------
    b : bool
        Returns True if the arrays are equal.

    See Also
    --------
    allclose: Returns True if two arrays are element-wise equal within a
              tolerance.
    array_equiv: Returns True if input arrays are shape consistent and all
                 elements equal.

    Examples
    --------
    >>> np.array_equal([1, 2], [1, 2])
    True
    >>> np.array_equal(np.array([1, 2]), np.array([1, 2]))
    True
    >>> np.array_equal([1, 2], [1, 2, 3])
    False
    >>> np.array_equal([1, 2], [1, 4])
    False

    """
    try:
        a1, a2 = asarray(a1), asarray(a2)
    except Exception:
        return False
    if a1.shape != a2.shape:
        return False
    return bool(asarray(a1 == a2).all()) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:42,代碼來源:numeric.py

示例5: test_array_equiv

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def test_array_equiv(self):
        res = np.array_equiv(np.array([1, 2]), np.array([1, 2]))
        assert_(res)
        assert_(type(res) is bool)
        res = np.array_equiv(np.array([1, 2]), np.array([1, 2, 3]))
        assert_(not res)
        assert_(type(res) is bool)
        res = np.array_equiv(np.array([1, 2]), np.array([3, 4]))
        assert_(not res)
        assert_(type(res) is bool)
        res = np.array_equiv(np.array([1, 2]), np.array([1, 3]))
        assert_(not res)
        assert_(type(res) is bool)

        res = np.array_equiv(np.array([1, 1]), np.array([1]))
        assert_(res)
        assert_(type(res) is bool)
        res = np.array_equiv(np.array([1, 1]), np.array([[1], [1]]))
        assert_(res)
        assert_(type(res) is bool)
        res = np.array_equiv(np.array([1, 2]), np.array([2]))
        assert_(not res)
        assert_(type(res) is bool)
        res = np.array_equiv(np.array([1, 2]), np.array([[1], [2]]))
        assert_(not res)
        assert_(type(res) is bool)
        res = np.array_equiv(np.array([1, 2]), np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]))
        assert_(not res)
        assert_(type(res) is bool) 
開發者ID:Frank-qlu,項目名稱:recruit,代碼行數:31,代碼來源:test_numeric.py

示例6: test_get_samples_audio

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def test_get_samples_audio():
    def get_samples_audio(audio):
        beat = audio.timings['beats'][0]
        samples, left_offset, right_offset = beat.get_samples()

        start = beat.time.delta * 1e-9
        duration = beat.duration.delta * 1e-9
        starting_sample, ending_sample = librosa.time_to_samples(
            [start, start + duration], beat.audio.sample_rate
        )
        left_offsets, right_offsets = beat._get_offsets(
            starting_sample, ending_sample, beat.audio.num_channels
        )

        start_sample = left_offsets[0] * -1
        end_sample = len(samples[0]) - left_offsets[1]
        reset_samples = samples[0][start_sample:end_sample]

        original_samples = audio.raw_samples[0, starting_sample:ending_sample]

        return reset_samples, original_samples

    mono_reset_samples, mono_original_samples = get_samples_audio(mono_audio)
    assert np.array_equiv(mono_reset_samples, mono_original_samples)

    stereo_reset_samples, stereo_original_samples = get_samples_audio(stereo_audio)
    assert np.array_equiv(stereo_reset_samples, stereo_original_samples) 
開發者ID:algorithmic-music-exploration,項目名稱:amen,代碼行數:29,代碼來源:test_timing.py

示例7: test_times_1

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def test_times_1():
    cntk_op = C.times([1, 2, 3], [[4], [5], [6]])
    cntk_ret = cntk_op.eval()

    ng_op, _ = CNTKImporter().import_model(cntk_op)
    ng_ret = ng.transformers.make_transformer().computation(ng_op)()

    assert np.array_equiv(cntk_ret, ng_ret) 
開發者ID:NervanaSystems,項目名稱:ngraph-python,代碼行數:10,代碼來源:test_ops_binary.py

示例8: test_times_2

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def test_times_2():
    cntk_op = C.times([[1, 2], [3, 4]], [[5, 6], [7, 8]])
    cntk_ret = cntk_op.eval()

    ng_op, _ = CNTKImporter().import_model(cntk_op)
    ng_ret = ng.transformers.make_transformer().computation(ng_op)()

    assert np.array_equiv(cntk_ret, ng_ret) 
開發者ID:NervanaSystems,項目名稱:ngraph-python,代碼行數:10,代碼來源:test_ops_binary.py

示例9: test_times_3

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def test_times_3():
    cntk_op = C.times([1, 2, 3], [[4, 5], [6, 7], [8, 9]])
    cntk_ret = cntk_op.eval()

    ng_op, _ = CNTKImporter().import_model(cntk_op)
    ng_ret = ng.transformers.make_transformer().computation(ng_op)()

    assert np.array_equiv(cntk_ret, ng_ret) 
開發者ID:NervanaSystems,項目名稱:ngraph-python,代碼行數:10,代碼來源:test_ops_binary.py

示例10: test_times_4

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def test_times_4():
    cntk_op = C.times([[1, 2, 3], [4, 5, 6]], [[7], [8], [9]])
    cntk_ret = cntk_op.eval()

    ng_op, _ = CNTKImporter().import_model(cntk_op)
    ng_ret = ng.transformers.make_transformer().computation(ng_op)()

    assert np.array_equiv(cntk_ret, ng_ret) 
開發者ID:NervanaSystems,項目名稱:ngraph-python,代碼行數:10,代碼來源:test_ops_binary.py

示例11: test_times_5

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def test_times_5():
    cntk_op = C.times([[1, 2, 3], [4, 5, 6]], [[7, 8], [9, 10], [11, 12]])
    cntk_ret = cntk_op.eval()

    ng_op, _ = CNTKImporter().import_model(cntk_op)
    ng_ret = ng.transformers.make_transformer().computation(ng_op)()

    assert np.array_equiv(cntk_ret, ng_ret) 
開發者ID:NervanaSystems,項目名稱:ngraph-python,代碼行數:10,代碼來源:test_ops_binary.py

示例12: test_decision_function

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def test_decision_function(self):
        ''' test for MiniClassifier.decision_function(X) '''
        X = self.util.load_sparse_csr("X_data.npz")
        dec = self.doc_clf.decision_function(X)  # [ 1.50563252]
        decTest = np.float64([1.50563252])
        ''' can't do:
            print(np.array_equal(dec, y))
            print(np.array_equiv(dec, y))
            since as decimals these will not pass
        '''
        self.assertTrue(np.allclose(dec, decTest)) 
開發者ID:ijmarshall,項目名稱:robotreviewer,代碼行數:13,代碼來源:test_ml.py

示例13: test_agglomerative_clustering_with_distance_threshold

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def test_agglomerative_clustering_with_distance_threshold(linkage):
    # Check that we obtain the correct number of clusters with
    # agglomerative clustering with distance_threshold.
    rng = np.random.RandomState(0)
    mask = np.ones([10, 10], dtype=np.bool)
    n_samples = 100
    X = rng.randn(n_samples, 50)
    connectivity = grid_to_graph(*mask.shape)
    # test when distance threshold is set to 10
    distance_threshold = 10
    for conn in [None, connectivity]:
        clustering = AgglomerativeClustering(
            n_clusters=None,
            distance_threshold=distance_threshold,
            connectivity=conn, linkage=linkage)
        clustering.fit(X)
        clusters_produced = clustering.labels_
        num_clusters_produced = len(np.unique(clustering.labels_))
        # test if the clusters produced match the point in the linkage tree
        # where the distance exceeds the threshold
        tree_builder = _TREE_BUILDERS[linkage]
        children, n_components, n_leaves, parent, distances = \
            tree_builder(X, connectivity=conn, n_clusters=None,
                         return_distance=True)
        num_clusters_at_threshold = np.count_nonzero(
            distances >= distance_threshold) + 1
        # test number of clusters produced
        assert num_clusters_at_threshold == num_clusters_produced
        # test clusters produced
        clusters_at_threshold = _hc_cut(n_clusters=num_clusters_produced,
                                        children=children,
                                        n_leaves=n_leaves)
        assert np.array_equiv(clusters_produced,
                              clusters_at_threshold) 
開發者ID:PacktPublishing,項目名稱:Mastering-Elasticsearch-7.0,代碼行數:36,代碼來源:test_hierarchical.py

示例14: fit

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def fit(self, X):
        groups = X.columns.to_series().groupby(X.dtypes).groups
        self.duplicate_cols = []
        for t, v in groups.items():
            cs = X[v].columns
            vs = X[v]
            lcs = len(cs)
            for i in range(lcs):
                ia = vs.iloc[:, i].values
                for j in range(i + 1, lcs):
                    ja = vs.iloc[:, j].values
                    if np.array_equiv(ia, ja):
                        self.duplicate_cols.append(cs[i])
                        break
        return self 
開發者ID:logicai-io,項目名稱:recsys2019,代碼行數:17,代碼來源:transformers.py

示例15: test_tri_sym_convert

# 需要導入模塊: import numpy [as 別名]
# 或者: from numpy import array_equiv [as 別名]
def test_tri_sym_convert():
    from brainiak.utils.utils import from_tri_2_sym, from_sym_2_tri
    import numpy as np

    sym = np.random.rand(3, 3)
    tri = from_sym_2_tri(sym)
    assert tri.shape[0] == 6,\
        "from_sym_2_tri returned wrong result!"
    sym1 = from_tri_2_sym(tri, 3)
    assert sym1.shape[0] == sym1.shape[1],\
        "from_tri_2_sym returned wrong shape!"
    tri1 = from_sym_2_tri(sym1)
    assert np.array_equiv(tri, tri1),\
        "from_sym_2_tri returned wrong result!" 
開發者ID:brainiak,項目名稱:brainiak,代碼行數:16,代碼來源:test_utils.py


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