本文整理汇总了Python中numpy.array_equal函数的典型用法代码示例。如果您正苦于以下问题:Python array_equal函数的具体用法?Python array_equal怎么用?Python array_equal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了array_equal函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_square_matrices_1
def test_square_matrices_1(self):
op4 = OP4()
# matrices = op4.read_op4(os.path.join(op4Path, fname))
form1 = 1
form2 = 2
form3 = 2
from numpy import matrix, ones, reshape, arange
A1 = matrix(ones((3, 3), dtype="float64"))
A2 = reshape(arange(9, dtype="float64"), (3, 3))
A3 = matrix(ones((1, 1), dtype="float32"))
matrices = {"A1": (form1, A1), "A2": (form2, A2), "A3": (form3, A3)}
for (is_binary, fname) in [(False, "small_ascii.op4"), (True, "small_binary.op4")]:
op4_filename = os.path.join(op4Path, fname)
op4.write_op4(op4_filename, matrices, name_order=None, precision="default", is_binary=False)
matrices2 = op4.read_op4(op4_filename, precision="default")
(form1b, A1b) = matrices2["A1"]
(form2b, A2b) = matrices2["A2"]
self.assertEqual(form1, form1b)
self.assertEqual(form2, form2b)
(form1b, A1b) = matrices2["A1"]
(form2b, A2b) = matrices2["A2"]
(form3b, A3b) = matrices2["A3"]
self.assertEqual(form1, form1b)
self.assertEqual(form2, form2b)
self.assertEqual(form3, form3b)
self.assertTrue(array_equal(A1, A1b))
self.assertTrue(array_equal(A2, A2b))
self.assertTrue(array_equal(A3, A3b))
del A1b, A2b, A3b
del form1b, form2b, form3b
示例2: testNegativeDelta
def testNegativeDelta(self):
self.assertTrue(
np.array_equal(self._Range(5, -1, -1), np.array([5, 4, 3, 2, 1, 0])))
self.assertTrue(
np.allclose(self._Range(2.5, 0, -0.5), np.array([2.5, 2, 1.5, 1, 0.5])))
self.assertTrue(
np.array_equal(self._Range(-5, -10, -3), np.array([-5, -8])))
示例3: test_train
def test_train(self):
# y = x + 0
x1 = np.array([2, 4])
y1 = np.array([2, 4])
m1 = LinearRegression(1)
m1.train(x1, y1, n_iter=1, lr=0.1)
# expected W and b after 1 iteration with lr 0.1
exp_W1 = np.array([1.0])
exp_b1 = 0.3
self.assertTrue(np.array_equal(m1.W, exp_W1))
self.assertAlmostEqual(m1.b[0], exp_b1)
# y = x1 + x2 + 0
x2 = np.array([[2, 2],
[4, 4]])
y2 = np.array([4, 8])
m2 = LinearRegression(2)
m2.train(x2, y2, n_iter=1, lr=0.1)
# expected W and b after 1 iteration with lr 0.1
exp_W2 = np.array([2.0, 2.0])
exp_b2 = 0.6
self.assertTrue(np.array_equal(m2.W, exp_W2))
self.assertAlmostEqual(m2.b[0], exp_b2)
示例4: _testFloodFill
def _testFloodFill(SegmentationHelper):
filledMask = SegmentationHelper._floodFill(
testImage, (1, 1), 5, connectivity=8)
assert numpy.array_equal(
filledMask,
numpy.array([
[255, 255, 0, 0, 0, 0],
[255, 255, 255, 255, 0, 0],
[0, 255, 0, 255, 255, 255],
[0, 255, 255, 255, 0, 0],
[0, 0, 255, 0, 0, 0],
[0, 0, 0, 255, 0, 0]
], dtype=numpy.uint8))
assert numpy.array_equal(testImage, originalTestImage)
# Now, with connectivity=4
filledMask = SegmentationHelper._floodFill(
testImage, (1, 1), 5, connectivity=4)
assert numpy.array_equal(
filledMask,
numpy.array([
[255, 255, 0, 0, 0, 0],
[255, 255, 255, 255, 0, 0],
[0, 255, 0, 255, 255, 255],
[0, 255, 255, 255, 0, 0],
[0, 0, 255, 0, 0, 0],
[0, 0, 0, 0, 0, 0]
], dtype=numpy.uint8))
assert numpy.array_equal(testImage, originalTestImage)
示例5: test_Moster13SmHm_behavior
def test_Moster13SmHm_behavior():
"""
"""
default_model = Moster13SmHm()
mstar1 = default_model.mean_stellar_mass(prim_haloprop = 1.e12)
ratio1 = mstar1/3.4275e10
np.testing.assert_array_almost_equal(ratio1, 1.0, decimal=3)
default_model.param_dict['n10'] *= 1.1
mstar2 = default_model.mean_stellar_mass(prim_haloprop = 1.e12)
assert mstar2 > mstar1
default_model.param_dict['n11'] *= 1.1
mstar3 = default_model.mean_stellar_mass(prim_haloprop = 1.e12)
assert mstar3 == mstar2
mstar4_z1 = default_model.mean_stellar_mass(prim_haloprop = 1.e12, redshift=1)
default_model.param_dict['n11'] *= 1.1
mstar5_z1 = default_model.mean_stellar_mass(prim_haloprop = 1.e12, redshift=1)
assert mstar5_z1 != mstar4_z1
mstar_realization1 = default_model.mc_stellar_mass(prim_haloprop = np.ones(1e4)*1e12, seed=43)
mstar_realization2 = default_model.mc_stellar_mass(prim_haloprop = np.ones(1e4)*1e12, seed=43)
mstar_realization3 = default_model.mc_stellar_mass(prim_haloprop = np.ones(1e4)*1e12, seed=44)
assert np.array_equal(mstar_realization1, mstar_realization2)
assert not np.array_equal(mstar_realization1, mstar_realization3)
measured_scatter1 = np.std(np.log10(mstar_realization1))
model_scatter = default_model.param_dict['scatter_model_param1']
np.testing.assert_allclose(measured_scatter1, model_scatter, rtol=1e-3)
default_model.param_dict['scatter_model_param1'] = 0.3
mstar_realization4 = default_model.mc_stellar_mass(prim_haloprop = np.ones(1e4)*1e12, seed=43)
measured_scatter4 = np.std(np.log10(mstar_realization4))
np.testing.assert_allclose(measured_scatter4, 0.3, rtol=1e-3)
示例6: test_A
def test_A(self):
cid0 = CORD2R()
Lx = 2.
Ly = 0.
Lz = 3.
Fy = 1.
origin = array([-Lx, 0., -Lz])
z_axis = origin + array([0., 0., 1.])
xz_plane = origin + array([1., 0., 1.])
rid = 0
data = [1, rid] + list(origin) + list(z_axis) + list(xz_plane)
Fxyz = [0., -Fy, 0.]
Mxyz = [0., 0., 0.]
cid_new = CORD2R(data=data)
model = None
Fxyz_local, Mxyz_local = TransformLoadWRT(Fxyz, Mxyz, cid0, cid_new,
model, is_cid_int=False)
r = array([Lx, Ly, Lz])
F = array([0., -Fy, 0.])
M = cross(r, F)
self.assertTrue(array_equal(Fxyz_local, F)), "expected=%s actual=%s" % (F, Fxyz_local)
self.assertTrue(array_equal(Mxyz_local, cross(r, F))), "expected=%s actual=%s" % (M, Mxyz_local)
示例7: test_Period
def test_Period():
p = Period(numbers[0:2], units[0])
assert sa_asserts.sa_access(p)
assert i_asserts.interval(p, start=numbers[0], stop=numbers[1])
assert np.array_equal(p.info['start'], p.start)
assert np.array_equal(p.info['stop'], p.stop)
assert np.array_equal(p.info['length'], p.length)
示例8: test_find_optimal_paras_rf
def test_find_optimal_paras_rf(self):
# first, load the file
f = h5py.File('tuning_ref_results/NIS_results.hdf5', 'r+')
# get the filter
grp = f['ICA/tuning']
wica = grp['Wica'][:] # should be
# get the reference results
ica_optx = grp.attrs['ica_optx']
ica_opty = grp.attrs['ica_opty']
ica_optfreq = grp.attrs['ica_optfreq']
ica_optor = grp.attrs['ica_optor']
ica_optphase = grp.attrs['ica_optphase']
# now shuffle this Wica. 1024x256
wica = transpose_c_and_f(wica.T)
# get result
result = tuning.find_optimal_paras_rf(w=wica, legacy=True)
# print result
self.assertTrue(np.allclose(result['optx'], ica_optx))
self.assertTrue(np.allclose(result['opty'], ica_opty))
self.assertTrue(np.array_equal(result['optfreq'], ica_optfreq))
self.assertTrue(np.array_equal(result['optor'], ica_optor))
self.assertTrue(np.array_equal(result['optphase'], ica_optphase))
f.close()
示例9: _read_volume_info
def _read_volume_info(fobj):
"""An implementation of nibabel.freesurfer.io._read_volume_info, since old
versions of nibabel (<=2.1.0) don't have it.
"""
volume_info = dict()
head = np.fromfile(fobj, '>i4', 1)
if not np.array_equal(head, [20]): # Read two bytes more
head = np.concatenate([head, np.fromfile(fobj, '>i4', 2)])
if not np.array_equal(head, [2, 0, 20]):
warnings.warn("Unknown extension code.")
return volume_info
volume_info['head'] = head
for key in ['valid', 'filename', 'volume', 'voxelsize', 'xras', 'yras',
'zras', 'cras']:
pair = fobj.readline().decode('utf-8').split('=')
if pair[0].strip() != key or len(pair) != 2:
raise IOError('Error parsing volume info.')
if key in ('valid', 'filename'):
volume_info[key] = pair[1].strip()
elif key == 'volume':
volume_info[key] = np.array(pair[1].split()).astype(int)
else:
volume_info[key] = np.array(pair[1].split()).astype(float)
# Ignore the rest
return volume_info
示例10: test_setPairMask
def test_setPairMask(self):
'''check different setPairMask arguments.
'''
bdc = self.bdc
dall = bdc(self.nickel)
bdc.maskAllPairs(False)
self.assertEqual(0, len(bdc(self.nickel)))
for i in range(4):
bdc.setPairMask(0, i, True)
dst0a = bdc(self.nickel)
bdc.setPairMask(range(4), 0, True, others=False)
dst0b = bdc(self.nickel)
self.assertTrue(numpy.array_equal(dst0a, dst0b))
bdc.maskAllPairs(False)
bdc.setPairMask(0, -7, True)
dst0c = bdc(self.nickel)
self.assertTrue(numpy.array_equal(dst0a, dst0c))
bdc.maskAllPairs(False)
bdc.setPairMask(0, 'all', True)
dst0d = bdc(self.nickel)
self.assertTrue(numpy.array_equal(dst0a, dst0d))
bdc.setPairMask('all', 'all', False)
self.assertEqual(0, len(bdc(self.nickel)))
bdc.setPairMask('all', range(4), True)
dall2 = bdc(self.nickel)
self.assertTrue(numpy.array_equal(dall, dall2))
self.assertRaises(ValueError, bdc.setPairMask, 'fooo', 2, True)
self.assertRaises(ValueError, bdc.setPairMask, 'aLL', 2, True)
return
示例11: test_tz_localize_dti
def test_tz_localize_dti(self):
from pandas.tseries.offsets import Hour
dti = DatetimeIndex(start='1/1/2005', end='1/1/2005 0:00:30.256',
freq='L')
dti2 = dti.tz_localize('US/Eastern')
dti_utc = DatetimeIndex(start='1/1/2005 05:00',
end='1/1/2005 5:00:30.256', freq='L',
tz='utc')
self.assert_(np.array_equal(dti2.values, dti_utc.values))
dti3 = dti2.tz_convert('US/Pacific')
self.assert_(np.array_equal(dti3.values, dti_utc.values))
dti = DatetimeIndex(start='11/6/2011 1:59',
end='11/6/2011 2:00', freq='L')
self.assertRaises(pytz.AmbiguousTimeError, dti.tz_localize,
'US/Eastern')
dti = DatetimeIndex(start='3/13/2011 1:59', end='3/13/2011 2:00',
freq='L')
self.assertRaises(pytz.AmbiguousTimeError, dti.tz_localize,
'US/Eastern')
示例12: test_tabulate
def test_tabulate():
scalar_no_units = lambda wlen: math.sqrt(wlen)
scalar_with_units = lambda wlen: math.sqrt(wlen.value)
array_no_units = lambda wlen: 1. + np.sqrt(wlen)
array_with_units = lambda wlen: np.sqrt(wlen.value)
add_units = lambda fval: (lambda wlen: fval(wlen) * u.erg)
wlen = np.arange(1, 3) * u.Angstrom
for v in True, False:
# Test each mode without any function return units.
f1 = tabulate_function_of_wavelength(scalar_no_units, wlen, v)
assert f1[1] == None
f2 = tabulate_function_of_wavelength(scalar_with_units, wlen, v)
assert f2[1] == None
f3 = tabulate_function_of_wavelength(array_no_units, wlen, v)
assert f3[1] == None
f4 = tabulate_function_of_wavelength(scalar_with_units, wlen, v)
assert f4[1] == None
# Now test with return units.
g1 = tabulate_function_of_wavelength(
add_units(scalar_no_units), wlen, v)
assert np.array_equal(f1[0], g1[0]) and g1[1] == u.erg
g2 = tabulate_function_of_wavelength(
add_units(scalar_with_units), wlen, v)
assert np.array_equal(f2[0], g2[0]) and g2[1] == u.erg
g3 = tabulate_function_of_wavelength(
add_units(array_no_units), wlen, v)
assert np.array_equal(f3[0], g3[0]) and g3[1] == u.erg
g4 = tabulate_function_of_wavelength(
add_units(scalar_with_units), wlen, v)
assert np.array_equal(f4[0], g4[0]) and g4[1] == u.erg
示例13: test_StatesMatrixMerger
def test_StatesMatrixMerger():
val_mat1_text = list(tools.ngram(test_text_df["text"].values[0], [1]))
val_mat2_text = list(tools.ngram(test_text_df["text"].values[1], [1]))
val_mat1 = ValuesMatrix(val_mat1_text, force2d="as_col")
val_mat2 = ValuesMatrix(val_mat2_text, force2d="as_col")
idx_data_mat1 = val_mat1.build_index_data_matrix()
idx_data_mat2 = val_mat2.build_index_data_matrix()
idx_data_mat1_old_ref_data = idx_data_mat1.states_matrix._ref_data
idx_data_mat2_old_ref_data = idx_data_mat2.states_matrix._ref_data
old_idx_data_mat1 = idx_data_mat1.index_matrix.copy()
old_idx_data_mat2 = idx_data_mat2.index_matrix.copy()
assert len(idx_data_mat1_old_ref_data) > 0
assert len(idx_data_mat2_old_ref_data) > 0
states_mats_merger = StatesMatrixMerger(idx_data_mat1.states_matrix,
idx_data_mat2.states_matrix)
assert len(states_mats_merger._unique_states_matrix_ids) > 1
states_mats_merger.update()
assert len(idx_data_mat1_old_ref_data) == 0
assert len(idx_data_mat2_old_ref_data) == 0
assert id(idx_data_mat1.states_matrix) == id(idx_data_mat2.states_matrix)
assert len(idx_data_mat2.states_matrix._ref_data) > 1
assert np.array_equal(idx_data_mat1.index_matrix, old_idx_data_mat1)
assert not np.array_equal(idx_data_mat2.index_matrix, old_idx_data_mat2)
assert np.array_equal(idx_data_mat1._data, val_mat1)
assert np.array_equal(idx_data_mat2._data, val_mat2)
示例14: test_two_triangles_without_edges
def test_two_triangles_without_edges():
grid = two_triangles_with_depths()
grid.edges = None
grid.save_as_netcdf("2_triangles_without_edges.nc")
# read it back in and check it out
ug = UGrid.from_ncfile("2_triangles_without_edges.nc", load_data=True)
assert ug.nodes.shape == (4, 2)
assert ug.nodes.shape == grid.nodes.shape
# not ideal to pull specific values out, but how else to test?
assert np.array_equal(ug.nodes[0, :], (0.1, 0.1))
assert np.array_equal(ug.nodes[-1, :], (3.1, 2.1))
assert np.array_equal(ug.nodes, grid.nodes)
assert ug.faces.shape == grid.faces.shape
assert ug.edges is None
depths = find_depths(ug)
assert depths.data.shape == (4,)
assert depths.data[0] == 1
assert depths.attributes["units"] == "unknown"
示例15: test_n_largest_area_contours_images__with_invert
def test_n_largest_area_contours_images__with_invert(self):
# given
image = cv2.imread("./images/SnipNLargestAreaContours/"
"test_n_largest_area_contours_image__with_invert__input_image.png",
cv2.IMREAD_GRAYSCALE)
n = 2
invert_flag = True
snip_n_largest_area_contours = SnipNLargestAreaContours(image, n, invert_flag)
expected_largest_contour_image_1 = cv2.imread(
"./images/SnipNLargestAreaContours/test_n_largest_area_contours_images__with_invert__snipped_image_1.png",
flags=cv2.IMREAD_GRAYSCALE)
expected_largest_contour_image_2 = cv2.imread(
"./images/SnipNLargestAreaContours/test_n_largest_area_contours_images__with_invert__snipped_image_2.png",
flags=cv2.IMREAD_GRAYSCALE)
expected_n_largest_area_contours_images = [expected_largest_contour_image_1, expected_largest_contour_image_2]
# when
actual_n_largest_area_contours_images = snip_n_largest_area_contours.n_largest_area_contours_images
# that
self.assertEqual(np.array_equal(actual_n_largest_area_contours_images[0],
expected_n_largest_area_contours_images[0]), True)
self.assertEqual(np.array_equal(actual_n_largest_area_contours_images[1],
expected_n_largest_area_contours_images[1]), True)