本文整理汇总了Python中xarray.Variable.stack方法的典型用法代码示例。如果您正苦于以下问题:Python Variable.stack方法的具体用法?Python Variable.stack怎么用?Python Variable.stack使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类xarray.Variable
的用法示例。
在下文中一共展示了Variable.stack方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_stack_errors
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import stack [as 别名]
def test_stack_errors(self):
v = Variable(['x', 'y'], [[0, 1], [2, 3]], {'foo': 'bar'})
with self.assertRaisesRegexp(ValueError, 'invalid existing dim'):
v.stack(z=('x1',))
with self.assertRaisesRegexp(ValueError, 'cannot create a new dim'):
v.stack(x=('x',))
示例2: test_unstack_errors
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import stack [as 别名]
def test_unstack_errors(self):
v = Variable('z', [0, 1, 2, 3])
with self.assertRaisesRegexp(ValueError, 'invalid existing dim'):
v.unstack(foo={'x': 4})
with self.assertRaisesRegexp(ValueError, 'cannot create a new dim'):
v.stack(z=('z',))
with self.assertRaisesRegexp(ValueError, 'the product of the new dim'):
v.unstack(z={'x': 5})
示例3: test_stack
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import stack [as 别名]
def test_stack(self):
v = Variable(['x', 'y'], [[0, 1], [2, 3]], {'foo': 'bar'})
actual = v.stack(z=('x', 'y'))
expected = Variable('z', [0, 1, 2, 3], v.attrs)
self.assertVariableIdentical(actual, expected)
actual = v.stack(z=('x',))
expected = Variable(('y', 'z'), v.data.T, v.attrs)
self.assertVariableIdentical(actual, expected)
actual = v.stack(z=(),)
self.assertVariableIdentical(actual, v)
actual = v.stack(X=('x',), Y=('y',)).transpose('X', 'Y')
expected = Variable(('X', 'Y'), v.data, v.attrs)
self.assertVariableIdentical(actual, expected)
示例4: test_stack
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import stack [as 别名]
def test_stack(self):
v = Variable(["x", "y"], [[0, 1], [2, 3]], {"foo": "bar"})
actual = v.stack(z=("x", "y"))
expected = Variable("z", [0, 1, 2, 3], v.attrs)
self.assertVariableIdentical(actual, expected)
actual = v.stack(z=("x",))
expected = Variable(("y", "z"), v.data.T, v.attrs)
self.assertVariableIdentical(actual, expected)
actual = v.stack(z=())
self.assertVariableIdentical(actual, v)
actual = v.stack(X=("x",), Y=("y",)).transpose("X", "Y")
expected = Variable(("X", "Y"), v.data, v.attrs)
self.assertVariableIdentical(actual, expected)
示例5: test_stack_unstack_consistency
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import stack [as 别名]
def test_stack_unstack_consistency(self):
v = Variable(['x', 'y'], [[0, 1], [2, 3]])
actual = (v.stack(z=('x', 'y'))
.unstack(z=OrderedDict([('x', 2), ('y', 2)])))
self.assertVariableIdentical(actual, v)
示例6: test_stack_unstack_consistency
# 需要导入模块: from xarray import Variable [as 别名]
# 或者: from xarray.Variable import stack [as 别名]
def test_stack_unstack_consistency(self):
v = Variable(["x", "y"], [[0, 1], [2, 3]])
actual = v.stack(z=("x", "y")).unstack(z=OrderedDict([("x", 2), ("y", 2)]))
self.assertVariableIdentical(actual, v)