当前位置: 首页>>代码示例>>Python>>正文


Python Variable.stack方法代码示例

本文整理汇总了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',))
开发者ID:joonro,项目名称:xarray,代码行数:9,代码来源:test_variable.py

示例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})
开发者ID:joonro,项目名称:xarray,代码行数:10,代码来源:test_variable.py

示例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)
开发者ID:joonro,项目名称:xarray,代码行数:18,代码来源:test_variable.py

示例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)
开发者ID:NicWayand,项目名称:xray,代码行数:18,代码来源:test_variable.py

示例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)
开发者ID:joonro,项目名称:xarray,代码行数:7,代码来源:test_variable.py

示例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)
开发者ID:NicWayand,项目名称:xray,代码行数:6,代码来源:test_variable.py


注:本文中的xarray.Variable.stack方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。