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


Python DataArray.axes方法代码示例

本文整理汇总了Python中datarray.datarray.DataArray.axes方法的典型用法代码示例。如果您正苦于以下问题:Python DataArray.axes方法的具体用法?Python DataArray.axes怎么用?Python DataArray.axes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在datarray.datarray.DataArray的用法示例。


在下文中一共展示了DataArray.axes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_axes_name_collision

# 需要导入模块: from datarray.datarray import DataArray [as 别名]
# 或者: from datarray.datarray.DataArray import axes [as 别名]
    def test_axes_name_collision(self):
        "Test .axes object for attribute collisions with axis names"
        A = DataArray(np.arange(6).reshape([1, 2, 3]), ("_arr", "_axes", "_namemap"))
        nt.assert_true(A.axes[0] is A.axes("_arr") is A.axes._arr)
        nt.assert_true(A.axes[1] is A.axes("_axes") is A.axes._axes)
        nt.assert_true(A.axes[2] is A.axes("_namemap") is A.axes._namemap)

        # Try to invoke some methods that use these attributes internally
        B = A[np.newaxis, ...]
        nt.assert_equal(B.shape, (1, 1, 2, 3))
        nt.assert_true(np.all(A + A == 2 * A))
开发者ID:BIDS,项目名称:datarray,代码行数:13,代码来源:test_data_array.py

示例2: setUp

# 需要导入模块: from datarray.datarray import DataArray [as 别名]
# 或者: from datarray.datarray.DataArray import axes [as 别名]
class TestAxesManager:
    def setUp(self):
        self.axes_spec = ('date', ('stocks', ('aapl', 'ibm', 'goog', 'msft')), 'metric')
        self.A = DataArray(np.random.randn(200, 4, 10), axes=self.axes_spec)

    def test_axes_name_collision(self):
        "Test .axes object for attribute collisions with axis names"
        A = DataArray(np.arange(6).reshape([1,2,3]), 
                ('_arr', '_axes', '_namemap'))
        nt.assert_true(A.axes[0] is A.axes('_arr') is A.axes._arr)
        nt.assert_true(A.axes[1] is A.axes('_axes') is A.axes._axes)
        nt.assert_true(A.axes[2] is A.axes('_namemap') is A.axes._namemap)
        
        # Try to invoke some methods that use these attributes internally
        B = A[np.newaxis, ...]
        nt.assert_equal(B.shape, (1,1,2,3))
        nt.assert_true(np.all(A + A == 2*A))

    def test_axes_numeric_access(self):
        for i,spec in enumerate(self.axes_spec):
            try:
                name,labels = spec
            except ValueError:
                name,labels = spec,None
            nt.assert_true(self.A.axes[i] == Axis(name=name, index=i,
                parent_arr=self.A, labels=labels))

    def test_axes_attribute_access(self):
        for spec in self.axes_spec:
            try:
                name,labels = spec
            except ValueError:
                name,labels = spec,None
            nt.assert_true(getattr(self.A.axes, name) is self.A.axes(name))

    def test_equality(self):
        B = DataArray(np.random.randn(200, 4, 10), axes=self.axes_spec)
        nt.assert_true(self.A.axes == B.axes)
        # What if axes differ by labels only?
        D = DataArray(np.random.randn(200, 4, 10), axes=('date', 'stocks', 'metric')) 
        nt.assert_false(self.A.axes == D.axes)
开发者ID:cfarrow,项目名称:datarray,代码行数:43,代码来源:test_data_array.py


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