Python numpy.array_equiv() Examples
The following are 30
code examples of numpy.array_equiv().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
numpy
, or try the search function
.
Example #1
Source File: weighting.py From odl with Mozilla Public License 2.0 | 6 votes |
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)
Example #2
Source File: test_state_orderbook.py From jesse with MIT License | 6 votes |
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)
Example #3
Source File: curriculum_test.py From LipNet with MIT License | 5 votes |
def show_results(_video, _align, video, align): show_video_subtitle(frames=_video.face, subtitle=_align.sentence) print "Video: " print _video.length print np.array_equiv(_video.mouth, video.mouth), print np.array_equiv(_video.data, video.data), print np.array_equiv(_video.face, video.face) print "Align: " print labels_to_text(_align.padded_label.astype(np.int)) print _align.padded_label print _align.label_length print np.array_equiv(_align.sentence, align.sentence), print np.array_equiv(_align.label, align.label), print np.array_equiv(_align.padded_label, align.padded_label)
Example #4
Source File: numeric.py From elasticintel with GNU General Public License v3.0 | 5 votes |
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: return False if a1.shape != a2.shape: return False return bool(asarray(a1 == a2).all())
Example #5
Source File: numeric.py From coffeegrindsize with MIT License | 5 votes |
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())
Example #6
Source File: __init__.py From DynaPhoPy with MIT License | 5 votes |
def _set_frequency_range(self, frequency_range): if not np.array_equiv(np.array(frequency_range), np.array(self.parameters.frequency_range)): self.power_spectra_clear() self.parameters.frequency_range = frequency_range
Example #7
Source File: test_numeric.py From elasticintel with GNU General Public License v3.0 | 5 votes |
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)
Example #8
Source File: test_quantity_non_ufuncs.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_array_equiv(self): q1 = np.array([[0., 1., 2.]]*3) * u.m q2 = q1[0].to(u.cm) assert np.array_equiv(q1, q2) q3 = q1[0].value * u.cm assert not np.array_equiv(q1, q3)
Example #9
Source File: numeric.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
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())
Example #10
Source File: numeric.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
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())
Example #11
Source File: test_numeric.py From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License | 5 votes |
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)
Example #12
Source File: numeric.py From twitter-stock-recommendation with MIT License | 5 votes |
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())
Example #13
Source File: test_numeric.py From twitter-stock-recommendation with MIT License | 5 votes |
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)
Example #14
Source File: test_numeric.py From keras-lambda with MIT License | 5 votes |
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)
Example #15
Source File: test_units.py From M-LOOP with MIT License | 5 votes |
def test_target_cost(self): cost_list = [1.,2.,-1.] interface = CostListInterface(cost_list) controller = mlc.create_controller(interface, max_num_runs = 10, target_cost = -1, max_num_runs_without_better_params = 4) controller.optimize() self.assertTrue(controller.best_cost == -1.) self.assertTrue(np.array_equiv(np.array(controller.in_costs), np.array(cost_list)))
Example #16
Source File: funcs.py From Numpy_arraysetops_EP with MIT License | 5 votes |
def unique(self, values): """Place each entry in a table, while asserting that each entry occurs once""" _, count = self.count() if not np.array_equiv(count, 1): raise ValueError("Not every entry in the table is assigned a unique value") return self.sum(values)
Example #17
Source File: numeric.py From Splunking-Crime with GNU Affero General Public License v3.0 | 5 votes |
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: return False if a1.shape != a2.shape: return False return bool(asarray(a1 == a2).all())
Example #18
Source File: __init__.py From sklearn2pmml with GNU Affero General Public License v3.0 | 5 votes |
def fit(self, X, y = None): rows, cols = X.shape mask = numpy.full((cols), True, dtype = bool) if isinstance(X, DataFrame): X = X.values for left in range(cols): if mask[left] is False: continue for right in range(left + 1, cols): equiv = numpy.array_equiv(X[:, left], X[:, right]) if(equiv): mask[right] = False self.support_mask_ = mask return self
Example #19
Source File: test_loop_steps.py From emukit with Apache License 2.0 | 5 votes |
def test_sequential_with_all_parameters_fixed(): mock_acquisition = mock.create_autospec(Acquisition) mock_acquisition.has_gradients = False mock_acquisition.evaluate = lambda x: np.sum(x**2, axis=1)[:, None] space = ParameterSpace([ContinuousParameter('x', 0, 1), ContinuousParameter('y', 0, 1)]) acquisition_optimizer = GradientAcquisitionOptimizer(space) loop_state_mock = mock.create_autospec(LoopState) seq = SequentialPointCalculator(mock_acquisition, acquisition_optimizer) next_points = seq.compute_next_points(loop_state_mock, context={'x': 0.25, 'y': 0.25}) assert np.array_equiv(next_points, np.array([0.25, 0.25]))
Example #20
Source File: test_loop_steps.py From emukit with Apache License 2.0 | 5 votes |
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 = np.random.rand(5, 1) cost = np.random.rand(5, 1) loop_state_mock.cost = cost updater.update(loop_state_mock) assert np.array_equiv(mock_model.X, cost)
Example #21
Source File: test_acquisition.py From emukit with Apache License 2.0 | 5 votes |
def test_acquisition_adding_with_gradients(): acquisition_sum = DummyAcquisitionWithGradients() + DummyAcquisitionWithGradients() acquisition_value, acquisition_grads = acquisition_sum.evaluate_with_gradients(np.array([[0]])) assert np.array_equal(acquisition_value, np.array([2.])) assert np.array_equiv(acquisition_grads, -np.array([2.]))
Example #22
Source File: test_kernels.py From emukit with Apache License 2.0 | 5 votes |
def test_k_full_and_k_diag_are_equivalent(): """ Test that kern.K and kern.Kdiag return equivalent results """ kernels = [] for i in range(0, 2): kernels.append(GPy.kern.RBF(1)) k = emukit.multi_fidelity.kernels.LinearMultiFidelityKernel(kernels) inputs = np.random.rand(20, 2) inputs[:10, 1] = 1 inputs[10:, 1] = 0 assert np.array_equiv(np.diag(k.K(inputs)), k.Kdiag(inputs))
Example #23
Source File: test_datasetattributes.py From pyvista with MIT License | 5 votes |
def test_append_string_array_should_equal(arr, hexbeam_field_attributes): hexbeam_field_attributes['string_arr'] = arr assert np.array_equiv(arr, hexbeam_field_attributes['string_arr'])
Example #24
Source File: lightfm.py From lightfm with Apache License 2.0 | 5 votes |
def _process_sample_weight(self, interactions, sample_weight): if sample_weight is not None: if self.loss == "warp-kos": raise NotImplementedError( "k-OS loss with sample weights " "not implemented." ) if not isinstance(sample_weight, sp.coo_matrix): raise ValueError("Sample_weight must be a COO matrix.") if sample_weight.shape != interactions.shape: raise ValueError( "Sample weight and interactions " "matrices must be the same shape" ) if not ( np.array_equal(interactions.row, sample_weight.row) and np.array_equal(interactions.col, sample_weight.col) ): raise ValueError( "Sample weight and interaction matrix " "entries must be in the same order" ) if sample_weight.data.dtype != CYTHON_DTYPE: sample_weight_data = sample_weight.data.astype(CYTHON_DTYPE) else: sample_weight_data = sample_weight.data else: if np.array_equiv(interactions.data, 1.0): # Re-use interactions data if they are all # ones sample_weight_data = interactions.data else: # Otherwise allocate a new array of ones sample_weight_data = np.ones_like(interactions.data, dtype=CYTHON_DTYPE) return sample_weight_data
Example #25
Source File: test_numeric.py From mxnet-lambda with Apache License 2.0 | 5 votes |
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)
Example #26
Source File: numeric.py From mxnet-lambda with Apache License 2.0 | 5 votes |
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: return False if a1.shape != a2.shape: return False return bool(asarray(a1 == a2).all())
Example #27
Source File: test_numeric.py From pySINDy with MIT License | 5 votes |
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)
Example #28
Source File: numeric.py From pySINDy with MIT License | 5 votes |
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())
Example #29
Source File: test_numpy.py From pyq with Apache License 2.0 | 5 votes |
def test_2d_roundtrip(dtype): a = numpy.zeros((3, 2), dtype) x = K(a) b = numpy.array(x) assert numpy.array_equiv(a, b)
Example #30
Source File: test_numpy.py From pyq with Apache License 2.0 | 5 votes |
def test_enum_to_array(q): x = q('`sym?`a`b') a = numpy.array(['a', 'b'], dtype=object) assert numpy.array_equiv(x, a)