本文整理汇总了Python中datarray.datarray.DataArray.flatten方法的典型用法代码示例。如果您正苦于以下问题:Python DataArray.flatten方法的具体用法?Python DataArray.flatten怎么用?Python DataArray.flatten使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类datarray.datarray.DataArray
的用法示例。
在下文中一共展示了DataArray.flatten方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_flatten_and_ravel
# 需要导入模块: from datarray.datarray import DataArray [as 别名]
# 或者: from datarray.datarray.DataArray import flatten [as 别名]
def test_flatten_and_ravel():
"Test the functionality of ravel() and flatten() methods"
d = DataArray(np.arange(20).reshape(4,5), 'xy')
df = d.flatten()
yield nt.assert_true, type(df) is np.ndarray, 'Type error in flatten'
yield nt.assert_true, df.shape == (20,), 'Wrong shape in flatten'
df[:4] = 0
yield nt.assert_false, (d[0,:4] == 0).all(), 'Copy not made in flatten'
dr = d.ravel()
yield nt.assert_true, type(dr) is np.ndarray, 'Type error in ravel'
yield nt.assert_true, dr.shape == (20,), 'Wrong shape in ravel'
dr[:4] = 0
yield nt.assert_true, (d[0,:4] == 0).all(), 'View not made in ravel'
示例2: test_flatten_and_ravel
# 需要导入模块: from datarray.datarray import DataArray [as 别名]
# 或者: from datarray.datarray.DataArray import flatten [as 别名]
def test_flatten_and_ravel():
"Test the functionality of ravel() and flatten() methods"
d = DataArray(np.arange(20).reshape(4, 5), "xy")
df = d.flatten()
nt.assert_true(type(df) is np.ndarray, "Type error in flatten")
nt.assert_true(df.shape == (20,), "Wrong shape in flatten")
df[:4] = 0
nt.assert_false((d[0, :4] == 0).all(), "Copy not made in flatten")
dr = d.ravel()
nt.assert_true(type(dr) is np.ndarray, "Type error in ravel")
nt.assert_true(dr.shape == (20,), "Wrong shape in ravel")
dr[:4] = 0
nt.assert_true((d[0, :4] == 0).all(), "View not made in ravel")