本文整理汇总了Python中xarray.Variable.concat方法的典型用法代码示例。如果您正苦于以下问题:Python Variable.concat方法的具体用法?Python Variable.concat怎么用?Python Variable.concat使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xarray.Variable
的用法示例。
在下文中一共展示了Variable.concat方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_concat
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import concat [as 别名]
def test_concat(self):
u = self.eager_var
v = self.lazy_var
self.assertLazyAndIdentical(u, Variable.concat([v[:2], v[2:]], 'x'))
self.assertLazyAndIdentical(u[:2], Variable.concat([v[0], v[1]], 'x'))
self.assertLazyAndIdentical(
u[:3], Variable.concat([v[[0, 2]], v[[1]]], 'x', positions=[[0, 2], [1]]))
示例2: test_concat_attrs
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import concat [as 别名]
def test_concat_attrs(self):
# different or conflicting attributes should be removed
v = self.cls("a", np.arange(5), {"foo": "bar"})
w = self.cls("a", np.ones(5))
expected = self.cls("a", np.concatenate([np.arange(5), np.ones(5)]))
self.assertVariableIdentical(expected, Variable.concat([v, w], "a"))
w.attrs["foo"] = 2
self.assertVariableIdentical(expected, Variable.concat([v, w], "a"))
w.attrs["foo"] = "bar"
expected.attrs["foo"] = "bar"
self.assertVariableIdentical(expected, Variable.concat([v, w], "a"))
示例3: test_concat_fixed_len_str
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import concat [as 别名]
def test_concat_fixed_len_str(self):
# regression test for #217
for kind in ["S", "U"]:
x = self.cls("animal", np.array(["horse"], dtype=kind))
y = self.cls("animal", np.array(["aardvark"], dtype=kind))
actual = Variable.concat([x, y], "animal")
expected = Variable("animal", np.array(["horse", "aardvark"], dtype=kind))
self.assertVariableEqual(expected, actual)
示例4: test_concat_number_strings
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import concat [as 别名]
def test_concat_number_strings(self):
# regression test for #305
a = self.cls('x', ['0', '1', '2'])
b = self.cls('x', ['3', '4'])
actual = Variable.concat([a, b], dim='x')
expected = Variable('x', np.arange(5).astype(str).astype(object))
self.assertVariableIdentical(expected, actual)
self.assertEqual(expected.dtype, object)
self.assertEqual(type(expected.values[0]), str)
示例5: test_concat_fixed_len_str
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import concat [as 别名]
def test_concat_fixed_len_str(self):
# regression test for #217
for kind in ['S', 'U']:
x = self.cls('animal', np.array(['horse'], dtype=kind))
y = self.cls('animal', np.array(['aardvark'], dtype=kind))
actual = Variable.concat([x, y], 'animal')
expected = Variable(
'animal', np.array(['horse', 'aardvark'], dtype=kind))
self.assertVariableEqual(expected, actual)
示例6: test_index_and_concat_datetime
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import concat [as 别名]
def test_index_and_concat_datetime(self):
# regression test for #125
date_range = pd.date_range('2011-09-01', periods=10)
for dates in [date_range, date_range.values,
date_range.to_pydatetime()]:
expected = self.cls('t', dates)
for times in [[expected[i] for i in range(10)],
[expected[i:(i + 1)] for i in range(10)],
[expected[[i]] for i in range(10)]]:
actual = Variable.concat(times, 't')
self.assertEqual(expected.dtype, actual.dtype)
self.assertArrayEqual(expected, actual)
示例7: test_concat
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import concat [as 别名]
def test_concat(self):
x = np.arange(5)
y = np.arange(5, 10)
v = self.cls(['a'], x)
w = self.cls(['a'], y)
self.assertVariableIdentical(Variable(['b', 'a'], np.array([x, y])),
Variable.concat([v, w], 'b'))
self.assertVariableIdentical(Variable(['b', 'a'], np.array([x, y])),
Variable.concat((v, w), 'b'))
self.assertVariableIdentical(Variable(['b', 'a'], np.array([x, y])),
Variable.concat((v, w), 'b'))
with self.assertRaisesRegexp(ValueError, 'inconsistent dimensions'):
Variable.concat([v, Variable(['c'], y)], 'b')
# test indexers
actual = Variable.concat([v, w], positions=[range(0, 10, 2),
range(1, 10, 2)], dim='a')
expected = Variable('a', np.array([x, y]).ravel(order='F'))
self.assertVariableIdentical(expected, actual)
# test concatenating along a dimension
v = Variable(['time', 'x'], np.random.random((10, 8)))
self.assertVariableIdentical(v, Variable.concat([v[:5], v[5:]], 'time'))
self.assertVariableIdentical(v, Variable.concat([v[:5], v[5:6], v[6:]], 'time'))
self.assertVariableIdentical(v, Variable.concat([v[:1], v[1:]], 'time'))
# test dimension order
self.assertVariableIdentical(v, Variable.concat([v[:, :5], v[:, 5:]], 'x'))
with self.assertRaisesRegexp(ValueError, 'all input arrays must have'):
Variable.concat([v[:, 0], v[:, 1:]], 'x')
示例8: test_concat
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import concat [as 别名]
def test_concat(self):
x = np.arange(5)
y = np.arange(5, 10)
v = self.cls(["a"], x)
w = self.cls(["a"], y)
self.assertVariableIdentical(Variable(["b", "a"], np.array([x, y])), Variable.concat([v, w], "b"))
self.assertVariableIdentical(Variable(["b", "a"], np.array([x, y])), Variable.concat((v, w), "b"))
self.assertVariableIdentical(Variable(["b", "a"], np.array([x, y])), Variable.concat((v, w), "b"))
with self.assertRaisesRegexp(ValueError, "inconsistent dimensions"):
Variable.concat([v, Variable(["c"], y)], "b")
# test indexers
actual = Variable.concat([v, w], positions=[np.arange(0, 10, 2), np.arange(1, 10, 2)], dim="a")
expected = Variable("a", np.array([x, y]).ravel(order="F"))
self.assertVariableIdentical(expected, actual)
# test concatenating along a dimension
v = Variable(["time", "x"], np.random.random((10, 8)))
self.assertVariableIdentical(v, Variable.concat([v[:5], v[5:]], "time"))
self.assertVariableIdentical(v, Variable.concat([v[:5], v[5:6], v[6:]], "time"))
self.assertVariableIdentical(v, Variable.concat([v[:1], v[1:]], "time"))
# test dimension order
self.assertVariableIdentical(v, Variable.concat([v[:, :5], v[:, 5:]], "x"))
with self.assertRaisesRegexp(ValueError, "all input arrays must have"):
Variable.concat([v[:, 0], v[:, 1:]], "x")