本文整理汇总了Python中datarray.datarray.DataArray.reshape方法的典型用法代码示例。如果您正苦于以下问题:Python DataArray.reshape方法的具体用法?Python DataArray.reshape怎么用?Python DataArray.reshape使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datarray.datarray.DataArray
的用法示例。
在下文中一共展示了DataArray.reshape方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_reshape_corners
# 需要导入模块: from datarray.datarray import DataArray [as 别名]
# 或者: from datarray.datarray.DataArray import reshape [as 别名]
def test_reshape_corners():
"Test some corner cases for reshape"
d = DataArray(np.random.randn(3,4,5), 'xyz')
d2 = d.reshape(-1)
yield nt.assert_true, d2.shape == (60,), 'Flattened shape wrong'
yield nt.assert_true, type(d2) is np.ndarray, 'Flattened type wrong'
d2 = d.reshape(60)
yield nt.assert_true, d2.shape == (60,), 'Flattened shape wrong'
yield nt.assert_true, type(d2) is np.ndarray, 'Flattened type wrong'
示例2: test_reshape_corners
# 需要导入模块: from datarray.datarray import DataArray [as 别名]
# 或者: from datarray.datarray.DataArray import reshape [as 别名]
def test_reshape_corners():
"Test some corner cases for reshape"
d = DataArray(np.random.randn(3, 4, 5), "xyz")
d2 = d.reshape(-1)
nt.assert_true(d2.shape == (60,), "Flattened shape wrong")
nt.assert_true(type(d2) is np.ndarray, "Flattened type wrong")
d2 = d.reshape(60)
nt.assert_true(d2.shape == (60,), "Flattened shape wrong")
nt.assert_true(type(d2) is np.ndarray, "Flattened type wrong")
示例3: test_reshape
# 需要导入模块: from datarray.datarray import DataArray [as 别名]
# 或者: from datarray.datarray.DataArray import reshape [as 别名]
def test_reshape():
d = DataArray(np.random.randn(3, 4, 5), "xyz")
new_shape = (1, 3, 1, 4, 5)
# Test padding the shape
d2 = d.reshape(new_shape)
new_labels = (None, "x", None, "y", "z")
nt.assert_true(d2.names == new_labels, "Array with inserted dimensions has wrong labels")
nt.assert_true(d2.shape == new_shape, "New shape wrong")
# Test trimming the shape
d3 = d2.reshape(d.shape)
nt.assert_true(d3.names == d.names, "Array with removed dimensions has wrong labels")
nt.assert_true(d3.shape == d.shape, "New shape wrong")
# Test a combo of padding and trimming
d4 = d2.reshape(3, 4, 1, 5, 1)
new_labels = ("x", "y", None, "z", None)
nt.assert_true(d4.names == new_labels, "Array with inserted and removed dimensions has wrong labels")
nt.assert_true(d4.shape == (3, 4, 1, 5, 1), "New shape wrong")
示例4: test_reshape
# 需要导入模块: from datarray.datarray import DataArray [as 别名]
# 或者: from datarray.datarray.DataArray import reshape [as 别名]
def test_reshape():
d = DataArray(np.random.randn(3,4,5), 'xyz')
new_shape = (1,3,1,4,5)
# Test padding the shape
d2 = d.reshape(new_shape)
new_labels = (None, 'x', None, 'y', 'z')
yield nt.assert_true, d2.labels == new_labels, \
'Array with inserted dimensions has wrong labels'
yield nt.assert_true, d2.shape == new_shape, 'New shape wrong'
# Test trimming the shape
d3 = d2.reshape(d.shape)
yield nt.assert_true, d3.labels == d.labels, \
'Array with removed dimensions has wrong labels'
yield nt.assert_true, d3.shape == d.shape, 'New shape wrong'
# Test a combo of padding and trimming
d4 = d2.reshape(3,4,1,5,1)
new_labels = ('x', 'y', None, 'z', None)
yield nt.assert_true, d4.labels == new_labels, \
'Array with inserted and removed dimensions has wrong labels'
yield nt.assert_true, d4.shape == (3,4,1,5,1), 'New shape wrong'