本文整理汇总了Python中numpy.array_equiv函数的典型用法代码示例。如果您正苦于以下问题:Python array_equiv函数的具体用法?Python array_equiv怎么用?Python array_equiv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_equiv函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_copy
def test_copy(self):
g = self.Grid
h = g.copy()
npt.assert_(np.array_equiv(g.domain[-1] - h.domain[-1], 0))
g.domain[-1] += 1
npt.assert_(not np.array_equiv(g.domain[-1] - h.domain[-1], 0))
return 0
开发者ID:johntyree,项目名称:fd_adi,代码行数:7,代码来源:test_Grid.py
示例2: test_RGB
def test_RGB():
"""
Test multi channel light class
"""
position = 10, 10
size = 50, 50
channels = 3
light = pylights.MultiLight('single_test', position, size, channels=channels)
old_value = np.array([0.8, 0.3, 0.6])
new_value = np.array([0.1, 0.1, 0.1])
light.set(old_value, False)
assert np.array_equiv(light.value_current, old_value)
assert np.array_equiv(light.value_target, old_value)
assert np.array_equiv(light.value_output, np.array([0, 0, 0]))
light.set(new_value)
assert np.array_equiv(light.value_current, old_value)
assert np.array_equiv(light.value_target, new_value)
assert np.array_equiv(light.value_output, np.array([0, 0, 0]))
light.update()
temp = (old_value + light.damping * (new_value - old_value))
assert np.array_equiv(light.value_current, temp)
assert np.array_equiv(light.value_target, new_value)
assert np.array_equiv(light.value_output, (old_value * 255.0).astype(int))
light.update()
assert np.array_equiv(light.value_output, (temp * 255.0).astype(int))
开发者ID:Denzo77,项目名称:PyLightShow,代码行数:25,代码来源:pylights_tests.py
示例3: __testSequences
def __testSequences(self, device, module):
module = str(module)
# Basic Interface: Currently supports read of all sequences only
#device.write("", "WORD_ADC_ENA", 1)
# Arrange the data on the card:
predefinedSequence = numpy.array([0x00010000,
0x00030002,
0x00050004,
0x00070006,
0x00090008,
0x000b000a,
0x000d000c,
0x000f000e,
0x00110010,
0x00130012,
0x00150014,
0x00170016,
0x00ff0018], dtype=numpy.int32)
device.write_raw(module, 'AREA_DMAABLE', predefinedSequence)
expectedMatrix = numpy.array([[0, 1, 2, 3],
[4, 5, 6, 7],
[8, 9, 10, 11],
[12, 13, 14, 15],
[16, 17, 18, 19],
[20, 21, 22, 23]], dtype=numpy.float32)
readInMatrix = device.read_sequences(module, 'DMA')
self.assertTrue(numpy.array_equiv(readInMatrix, expectedMatrix))
self.assertTrue(readInMatrix.dtype == numpy.float32)
readInMatrix = device.read_sequences(registerPath = '/' + str(module)+ '/DMA')
self.assertTrue(numpy.array_equiv(readInMatrix, expectedMatrix))
self.assertTrue(readInMatrix.dtype == numpy.float32)
开发者ID:ChimeraTK,项目名称:DeviceAccess-PythonBindings,代码行数:32,代码来源:testMtca4upy.py
示例4: bin2d_cvt_equal_mass
def bin2d_cvt_equal_mass(self, wvt=None, verbose=1) :
"""
Produce a CV Tesselation
wvt: default is None (will use preset value, see self.wvt)
"""
## Reset the status and statusnode for all nodes
self.status = np.zeros(self.npix, dtype=Nint)
self.statusnode = np.arange(self.xnode.size) + 1
if wvt is not None : self.wvt = wvt
if self.wvt : self.weight = np.ones_like(self.data)
else : self.weight = self.data**4
self.scale = 1.0
self.niter = 0
## WHILE LOOP: stop when the nodes do not move anymore ============
Oldxnode, Oldynode = copy.copy(self.xnode[-1]), copy.copy(self.ynode[-1])
while (not np.array_equiv(self.xnode, Oldxnode)) | (not np.array_equiv(self.ynode, Oldynode)):
Oldxnode, Oldynode = copy.copy(self.xnode), copy.copy(self.ynode)
## Assign the closest centroid to each bin
self.bin2d_assign_bins()
## New nodes weighted centroids
self.bin2d_weighted_centroid()
## Eq. (4) of Diehl & Statler (2006)
if self.wvt : self.scale = sqrt(self.Areanode/self.flux_node)
self.niter += 1
开发者ID:tammojan,项目名称:LSMTool,代码行数:31,代码来源:_tessellate.py
示例5: equiv
def equiv(self, other):
"""Test if other is an equivalent weighting.
Returns
-------
equivalent : `bool`
`True` if other is a `WeightingBase` instance with the same
`WeightingBase.impl`, which yields the same result as this
weighting for any input, `False` otherwise. This is checked
by entry-wise comparison of matrices/vectors/constants.
"""
# Optimization for equality
if self == other:
return True
elif self.exponent != getattr(other, 'exponent', -1):
return False
elif isinstance(other, MatrixWeightingBase):
if self.matrix.shape != other.matrix.shape:
return False
if self.matrix_issparse:
if other.matrix_issparse:
# Optimization for different number of nonzero elements
if self.matrix.nnz != other.matrix.nnz:
return False
else:
# Most efficient out-of-the-box comparison
return (self.matrix != other.matrix).nnz == 0
else: # Worst case: compare against dense matrix
return np.array_equal(self.matrix.todense(), other.matrix)
else: # matrix of `self` is dense
if other.matrix_issparse:
return np.array_equal(self.matrix, other.matrix.todense())
else:
return np.array_equal(self.matrix, other.matrix)
elif isinstance(other, VectorWeightingBase):
if self.matrix_issparse:
return (np.array_equiv(self.matrix.diagonal(),
other.vector) and
np.array_equal(self.matrix.asformat('dia').offsets,
np.array([0])))
else:
return np.array_equal(
self.matrix, other.vector * np.eye(self.matrix.shape[0]))
elif isinstance(other, ConstWeightingBase):
if self.matrix_issparse:
return (np.array_equiv(self.matrix.diagonal(), other.const) and
np.array_equal(self.matrix.asformat('dia').offsets,
np.array([0])))
else:
return np.array_equal(
self.matrix, other.const * np.eye(self.matrix.shape[0]))
else:
return False
开发者ID:NikEfth,项目名称:odl,代码行数:59,代码来源:weighting.py
示例6: test_xls_contents
def test_xls_contents():
sample = Sample.from_file(from_current_dir('sample2.xlsx'))
expected_attributes = array([[1], [2], [3], [4], [5]])
expected_categories = array([1, 2, 3, 4, 5])
expected_columns = ["Age"]
assert array_equiv(sample.attributes, expected_attributes)
assert array_equiv(sample.categories, expected_categories)
assert sample.columns == expected_columns
开发者ID:tolkjen,项目名称:Degree,代码行数:8,代码来源:test_sample.py
示例7: test_from_file_with_indices
def test_from_file_with_indices():
sample = Sample.from_file(from_current_dir('sample2.xlsx'), [0, 4])
expected_attributes = array([[1], [5]])
expected_categories = array([1, 5])
expected_columns = ["Age"]
assert array_equiv(sample.attributes, expected_attributes)
assert array_equiv(sample.categories, expected_categories)
assert sample.columns == expected_columns
开发者ID:tolkjen,项目名称:Degree,代码行数:8,代码来源:test_sample.py
示例8: test_equivalent
def test_equivalent(self):
"""
Returns True if input arrays are shape consistent and all elements equal.
Shape consistent means they are either the same shape,
or one input array can be broadcasted to create the same shape as the other one.
"""
a = [1,2]
b = np.asarray(a)
self.assertTrue(np.array_equiv(a, b))
self.assertTrue(np.array_equiv(a,[a,a]))
开发者ID:stasi009,项目名称:TestDrivenLearn,代码行数:10,代码来源:test_ndarray_compare.py
示例9: test_transform
def test_transform():
sample = Sample.from_file(from_current_dir('sample3.xlsx'))
sample.merge_columns(['One', 'Three'], TestClusterer(), 'New')
expected_attributes = array([[2, 0], [2, 0]])
expected_categories = array([0, 0])
expected_columns = ['Two', 'New']
assert array_equiv(sample.attributes, expected_attributes)
assert array_equiv(sample.categories, expected_categories)
assert sample.columns == expected_columns
开发者ID:tolkjen,项目名称:Degree,代码行数:10,代码来源:test_sample.py
示例10: test_remove_existing_column
def test_remove_existing_column():
sample = Sample.from_file(from_current_dir('sample3.xlsx'))
sample.remove_column('Two')
expected_attributes = array([[1, 3], [1, 3]])
expected_categories = array([0, 0])
expected_columns = ['One', 'Three']
assert array_equiv(sample.attributes, expected_attributes)
assert array_equiv(sample.categories, expected_categories)
assert sample.columns == expected_columns
开发者ID:tolkjen,项目名称:Degree,代码行数:10,代码来源:test_sample.py
示例11: test_normalize_existing_column
def test_normalize_existing_column():
sample = Sample.from_file(from_current_dir('sample2.xlsx'))
normalizer = sample.get_normalizer((0.0, 1.0))
sample.normalize(normalizer, ["Age"])
expected_attributes = array([[0.0], [0.25], [0.5], [0.75], [1.0]])
expected_categories = array([1, 2, 3, 4, 5])
expected_columns = ["Age"]
assert array_equiv(sample.attributes, expected_attributes)
assert array_equiv(sample.categories, expected_categories)
assert sample.columns == expected_columns
开发者ID:tolkjen,项目名称:Degree,代码行数:11,代码来源:test_sample.py
示例12: _checkSameExperimentResults
def _checkSameExperimentResults(exp1, exp2):
""" Returns False if experiments gave same results, true if they match. """
if not np.array_equiv(exp1.result["learning_steps"], exp2.result["learning_steps"]):
# Same number of steps before failure (where applicable)
return False
if not np.array_equiv(exp1.result["return"], exp2.result["return"]):
# Same return on each test episode
return False
if not np.array_equiv(exp1.result["steps"], exp2.result["steps"]):
# Same number of steps taken on each training episode
return False
return True
开发者ID:okkhoy,项目名称:rlpy,代码行数:12,代码来源:test_SystemAdministrator.py
示例13: _equal
def _equal(a, b):
#recursion on subclasses of types: tuple, list, dict
#specifically checks : float, ndarray
if type(a) is float and type(b) is float:#float
return(numpy.allclose(a, b))
elif type(a) is numpy.ndarray and type(b) is numpy.ndarray:#ndarray
return(numpy.array_equiv(a, b))#alternative for float-arrays: numpy.allclose(a, b[, rtol, atol])
elif isinstance(a, dict) and isinstance(b, dict):#dict
if len(a) != len(b):
return(False)
t = True
for key, val in a.items():
if key not in b:
return(False)
t = _equal(val, b[key])
if not t:
return(False)
return(t)
elif (isinstance(a, list) and isinstance(b, list)) or (isinstance(a, tuple) and isinstance(b, tuple)):#list, tuples
if len(a) != len(b):
return(False)
t = True
for vala, valb in zip(a, b):
t = _equal(vala, valb)
if not t:
return(False)
return(t)
else:#fallback
return(a == b)
开发者ID:esampson,项目名称:worldengine,代码行数:29,代码来源:common.py
示例14: test_agglomerative_clustering_with_distance_threshold
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:kevin-coder,项目名称:scikit-learn-fork,代码行数:34,代码来源:test_hierarchical.py
示例15: exp
def exp(xi,tau=None):
#given a 6x1 vector returns a SE3 object
#may output garbage if matrix not invertible
c=np.zeros((3,1))
xiHat=SE3.hat(xi)
v=np.array([[xiHat[0,3]],
[xiHat[1,3]],
[xiHat[2,3]]])
w=np.array([[xiHat[2,1]],
[xiHat[0,2]],
[xiHat[1,0]]])
wtrans=w.T
what=xiHat[0:3,0:3]
normw=np.linalg.norm(w)
w2=w.dot(wtrans)-math.pow(normw,2)*np.eye(3)
if tau==None:
tau=1
print tau
if np.array_equiv(w,c)==False:
ewt=np.eye(3)+(what/normw)*math.sin(tau*normw)+w2*(1-math.cos(normw*tau))/math.pow(normw,2)
d1=np.eye(3)-ewt
d2=d1.dot(what)/math.pow(normw,2)
d3=d2.dot(v)
d32=(w.dot(wtrans).dot(v)*tau)/math.pow(normw,2)
d=d3+d32
else:
ewt=np.eye(3)
d=v*tau
expXi=np.concatenate((np.concatenate((ewt,d),axis=1),np.array([[0,0,0,1]])),axis=0)
omegatau=SE3()
omegatau.__M=expXi
return omegatau
开发者ID:rtull3,项目名称:Terrabots-Work,代码行数:32,代码来源:SE3.py
示例16: test_coverage_recovery
def test_coverage_recovery(self):
# Create the coverage
cov, dset = self.get_cov()
if cov._persistence_layer.master_manager.storage_type() != 'hdf':
# TODO: Check for something Cassandra related
self.assertTrue(True)
else:
cov_pth = cov.persistence_dir
cov.close()
# Analyze the valid coverage
dr = CoverageDoctor(cov_pth, 'dprod', dset)
dr_result = dr.analyze()
# TODO: Turn these into meaningful Asserts
self.assertEqual(len(dr_result.get_brick_corruptions()), 0)
self.assertEqual(len(dr_result.get_brick_size_ratios()), 6)
self.assertEqual(len(dr_result.get_corruptions()), 0)
self.assertEqual(len(dr_result.get_master_corruption()), 0)
self.assertEqual(len(dr_result.get_param_corruptions()), 0)
self.assertEqual(len(dr_result.get_param_size_ratios()), 3)
self.assertEqual(len(dr_result.get_master_size_ratio()), 1)
self.assertEqual(len(dr_result.get_size_ratios()), 10)
self.assertEqual(dr_result.master_status[1], 'NORMAL')
self.assertFalse(dr_result.is_corrupt)
self.assertEqual(dr_result.param_file_count, 3)
self.assertEqual(dr_result.brick_file_count, 6)
self.assertEqual(dr_result.total_file_count, 10)
# Get original values (mock)
orig_cov = AbstractCoverage.load(cov_pth)
time_vals_orig = orig_cov.get_time_values()
orig_cov.close()
# Corrupt the Master File
fo = open(cov._persistence_layer.master_manager.file_path, "wb")
fo.write('Junk')
fo.close()
# Corrupt the lon Parameter file
fo = open(cov._persistence_layer.parameter_metadata['lon'].file_path, "wb")
fo.write('Junk')
fo.close()
corrupt_res = dr.analyze(reanalyze=True)
self.assertTrue(corrupt_res.is_corrupt)
# Repair the metadata files
dr.repair(reanalyze=True)
fixed_res = dr.analyze(reanalyze=True)
self.assertFalse(fixed_res.is_corrupt)
fixed_cov = AbstractCoverage.load(cov_pth)
self.assertIsInstance(fixed_cov, AbstractCoverage)
time_vals_fixed = fixed_cov.get_time_values()
fixed_cov.close()
self.assertTrue(np.array_equiv(time_vals_orig, time_vals_fixed))
开发者ID:ooici,项目名称:coverage-model,代码行数:60,代码来源:test_recovery.py
示例17: test_every_iteration_model_updater_with_cost
def test_every_iteration_model_updater_with_cost():
"""
Tests that the model updater can use a different attribute from loop_state as the training targets
"""
class MockModel(IModel):
def optimize(self):
pass
def set_data(self, X: np.ndarray, Y: np.ndarray):
self._X = X
self._Y = Y
@property
def X(self):
return self._X
@property
def Y(self):
return self._Y
mock_model = MockModel()
updater = FixedIntervalUpdater(mock_model, 1, lambda loop_state: loop_state.cost)
loop_state_mock = mock.create_autospec(LoopState)
loop_state_mock.iteration = 1
loop_state_mock.X.return_value(np.random.rand(5, 1))
loop_state_mock.cost.return_value(np.random.rand(5, 1))
cost = np.random.rand(5, 1)
loop_state_mock.cost.return_value(cost)
updater.update(loop_state_mock)
assert np.array_equiv(mock_model.X, cost)
开发者ID:JRetza,项目名称:emukit,代码行数:33,代码来源:test_loop_steps.py
示例18: _compute_alpha
def _compute_alpha(self, y):
# Recalculate alpha only if y is not the same as the previous y.
if self._alpha is None or not np.array_equiv(y, self._y):
self._y = y
r = np.ascontiguousarray(self._check_dimensions(y)[self.inds]
- self.mean(self._x), dtype=np.float64)
self._alpha = self.solver.apply_inverse(r, in_place=True)
开发者ID:DiNAi,项目名称:george,代码行数:7,代码来源:gp.py
示例19: test_impute
def test_impute():
d = PreprocessingDescriptor("mean", [], [], [])
sample = Sample.from_file(from_current_dir("sample6.xlsx"))
impute_model = d.impute(sample)
sample.impute_nan(impute_model)
assert array_equiv(sample.attributes, [[3], [3], [3], [3], [3]])
开发者ID:tolkjen,项目名称:Degree,代码行数:7,代码来源:test_descriptors.py
示例20: _test_patch_at
def _test_patch_at():
size = (101, 101)
orig = cv2.imread(os.path.abspath('tests/patch_at/test.tiff'))
image = img2np(cv2.copyMakeBorder(orig, top=size[1], bottom=size[1], left=size[0], right=size[0],
borderType=cv2.BORDER_DEFAULT))
patch_0_0 = img2np(cv2.imread(os.path.abspath('tests/patch_at/patch_0_0.tiff')))
patch_300_500 = img2np(cv2.imread(os.path.abspath('tests/patch_at/patch_300_500.tiff')))
patch_500_300 = img2np(cv2.imread(os.path.abspath('tests/patch_at/patch_500_300.tiff')))
pixels = [(51, 51), (351, 551), (551, 351)]
outputs = (patch_0_0, patch_300_500, patch_500_300)
for (x, y), expected in zip(pixels, outputs):
actual = patch_at(image=image, x=x, y=y, size=size)
actual = normalize(actual)
expected = normalize(expected)
try:
assert np.array_equiv(expected, actual)
except AssertionError:
print "Failed: ", (x, y), expected.shape, actual.shape
import pylab
f = pylab.figure()
f.add_subplot(3, 1, 1)
pylab.imshow(np2img(actual))
f.add_subplot(3, 1, 2)
pylab.imshow(np2img(expected))
f.add_subplot(3, 1, 3)
diff = expected - actual
pylab.imshow(np2img(diff))
from scipy.linalg import norm
print "Norms: ", np.sum(np.abs(diff)), norm(diff.ravel(), 0)
pylab.show()
开发者ID:DeeperCS,项目名称:mitosis-detection,代码行数:30,代码来源:helpers.py
注:本文中的numpy.array_equiv函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论