Пример #1
0
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
0
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'
Пример #3
0
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")
Пример #4
0
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")
Пример #5
0
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'
Пример #6
0
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.names == 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.names == d.names, \
          '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.names == 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'