本文整理汇总了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)
示例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)
示例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) #####
示例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())
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)
示例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))
示例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)
示例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
示例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!"