Python numpy.nested_iters() Examples

The following are 30 code examples of numpy.nested_iters(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module numpy , or try the search function .
Example #1
Source File: test_nditer.py    From Mastering-Elasticsearch-7.0 with MIT License 6 votes vote down vote up
def test_0d(self):
        a = np.arange(12).reshape(2, 3, 2)
        i, j = np.nested_iters(a, [[], [1, 0, 2]])
        vals = [list(j) for _ in i]
        assert_equal(vals, [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])

        i, j = np.nested_iters(a, [[1, 0, 2], []])
        vals = [list(j) for _ in i]
        assert_equal(vals, [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]])

        i, j, k = np.nested_iters(a, [[2, 0], [], [1]])
        vals = []
        for x in i:
            for y in j:
                vals.append([z for z in k])
        assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #2
Source File: test_nditer.py    From pySINDy with MIT License 6 votes vote down vote up
def test_0d(self):
        a = np.arange(12).reshape(2, 3, 2)
        i, j = np.nested_iters(a, [[], [1, 0, 2]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])

        i, j = np.nested_iters(a, [[1, 0, 2], []])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]])

        i, j, k = np.nested_iters(a, [[2, 0], [], [1]])
        vals = []
        for x in i:
            for y in j:
                vals.append([z for z in k])
        assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #3
Source File: test_nditer.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def test_iter_nested_iters_broadcast():
    # Test nested iteration with broadcasting
    a = arange(2).reshape(2, 1)
    b = arange(3).reshape(1, 3)

    i, j = np.nested_iters([a, b], [[0], [1]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]]])

    i, j = np.nested_iters([a, b], [[1], [0]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[[0, 0], [1, 0]], [[0, 1], [1, 1]], [[0, 2], [1, 2]]]) 
Example #4
Source File: test_nditer.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def test_0d_nested_iter():
    a = np.arange(12).reshape(2, 3, 2)
    i, j = np.nested_iters(a, [[], [1, 0, 2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])

    i, j = np.nested_iters(a, [[1, 0, 2], []])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]])

    i, j, k = np.nested_iters(a, [[2, 0], [], [1]])
    vals = []
    for x in i:
        for y in j:
            vals.append([z for z in k])
    assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #5
Source File: test_nditer.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_basic(self):
        # Test nested iteration basic usage
        a = arange(12).reshape(2, 3, 2)

        i, j = np.nested_iters(a, [[0], [1, 2]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]])

        i, j = np.nested_iters(a, [[0, 1], [2]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]])

        i, j = np.nested_iters(a, [[0, 2], [1]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #6
Source File: test_nditer.py    From mxnet-lambda with Apache License 2.0 6 votes vote down vote up
def test_iter_nested_iters_basic():
    # Test nested iteration basic usage
    a = arange(12).reshape(2, 3, 2)

    i, j = np.nested_iters(a, [[0], [1, 2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]])

    i, j = np.nested_iters(a, [[0, 1], [2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]])

    i, j = np.nested_iters(a, [[0, 2], [1]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #7
Source File: test_nditer.py    From ImageFusion with MIT License 6 votes vote down vote up
def test_iter_nested_iters_basic():
    # Test nested iteration basic usage
    a = arange(12).reshape(2, 3, 2)

    i, j = np.nested_iters(a, [[0], [1, 2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]])

    i, j = np.nested_iters(a, [[0, 1], [2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]])

    i, j = np.nested_iters(a, [[0, 2], [1]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #8
Source File: test_nditer.py    From auto-alt-text-lambda-api with MIT License 6 votes vote down vote up
def test_iter_nested_iters_basic():
    # Test nested iteration basic usage
    a = arange(12).reshape(2, 3, 2)

    i, j = np.nested_iters(a, [[0], [1, 2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]])

    i, j = np.nested_iters(a, [[0, 1], [2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]])

    i, j = np.nested_iters(a, [[0, 2], [1]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #9
Source File: test_nditer.py    From pySINDy with MIT License 6 votes vote down vote up
def test_broadcast(self):
        # Test nested iteration with broadcasting
        a = arange(2).reshape(2, 1)
        b = arange(3).reshape(1, 3)

        i, j = np.nested_iters([a, b], [[0], [1]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]]])

        i, j = np.nested_iters([a, b], [[1], [0]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[[0, 0], [1, 0]], [[0, 1], [1, 1]], [[0, 2], [1, 2]]]) 
Example #10
Source File: test_nditer.py    From recruit with Apache License 2.0 6 votes vote down vote up
def test_0d(self):
        a = np.arange(12).reshape(2, 3, 2)
        i, j = np.nested_iters(a, [[], [1, 0, 2]])
        vals = [list(j) for _ in i]
        assert_equal(vals, [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])

        i, j = np.nested_iters(a, [[1, 0, 2], []])
        vals = [list(j) for _ in i]
        assert_equal(vals, [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]])

        i, j, k = np.nested_iters(a, [[2, 0], [], [1]])
        vals = []
        for x in i:
            for y in j:
                vals.append([z for z in k])
        assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #11
Source File: test_nditer.py    From coffeegrindsize with MIT License 6 votes vote down vote up
def test_0d(self):
        a = np.arange(12).reshape(2, 3, 2)
        i, j = np.nested_iters(a, [[], [1, 0, 2]])
        vals = [list(j) for _ in i]
        assert_equal(vals, [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])

        i, j = np.nested_iters(a, [[1, 0, 2], []])
        vals = [list(j) for _ in i]
        assert_equal(vals, [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]])

        i, j, k = np.nested_iters(a, [[2, 0], [], [1]])
        vals = []
        for x in i:
            for y in j:
                vals.append([z for z in k])
        assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #12
Source File: test_nditer.py    From pySINDy with MIT License 6 votes vote down vote up
def test_basic(self):
        # Test nested iteration basic usage
        a = arange(12).reshape(2, 3, 2)

        i, j = np.nested_iters(a, [[0], [1, 2]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]])

        i, j = np.nested_iters(a, [[0, 1], [2]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]])

        i, j = np.nested_iters(a, [[0, 2], [1]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #13
Source File: test_nditer.py    From Serverless-Deep-Learning-with-TensorFlow-and-AWS-Lambda with MIT License 6 votes vote down vote up
def test_basic(self):
        # Test nested iteration basic usage
        a = arange(12).reshape(2, 3, 2)

        i, j = np.nested_iters(a, [[0], [1, 2]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]])

        i, j = np.nested_iters(a, [[0, 1], [2]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]])

        i, j = np.nested_iters(a, [[0, 2], [1]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #14
Source File: test_nditer.py    From mxnet-lambda with Apache License 2.0 6 votes vote down vote up
def test_0d_nested_iter():
    a = np.arange(12).reshape(2, 3, 2)
    i, j = np.nested_iters(a, [[], [1, 0, 2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])

    i, j = np.nested_iters(a, [[1, 0, 2], []])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]])

    i, j, k = np.nested_iters(a, [[2, 0], [], [1]])
    vals = []
    for x in i:
        for y in j:
            vals.append([z for z in k])
    assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #15
Source File: test_nditer.py    From predictive-maintenance-using-machine-learning with Apache License 2.0 6 votes vote down vote up
def test_0d(self):
        a = np.arange(12).reshape(2, 3, 2)
        i, j = np.nested_iters(a, [[], [1, 0, 2]])
        vals = [list(j) for _ in i]
        assert_equal(vals, [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])

        i, j = np.nested_iters(a, [[1, 0, 2], []])
        vals = [list(j) for _ in i]
        assert_equal(vals, [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]])

        i, j, k = np.nested_iters(a, [[2, 0], [], [1]])
        vals = []
        for x in i:
            for y in j:
                vals.append([z for z in k])
        assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #16
Source File: test_nditer.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_broadcast(self):
        # Test nested iteration with broadcasting
        a = arange(2).reshape(2, 1)
        b = arange(3).reshape(1, 3)

        i, j = np.nested_iters([a, b], [[0], [1]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]]])

        i, j = np.nested_iters([a, b], [[1], [0]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[[0, 0], [1, 0]], [[0, 1], [1, 1]], [[0, 2], [1, 2]]]) 
Example #17
Source File: test_nditer.py    From GraphicDesignPatternByPython with MIT License 6 votes vote down vote up
def test_basic(self):
        # Test nested iteration basic usage
        a = arange(12).reshape(2, 3, 2)

        i, j = np.nested_iters(a, [[0], [1, 2]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]])

        i, j = np.nested_iters(a, [[0, 1], [2]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]])

        i, j = np.nested_iters(a, [[0, 2], [1]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #18
Source File: test_nditer.py    From vnpy_crypto with MIT License 6 votes vote down vote up
def test_0d(self):
        a = np.arange(12).reshape(2, 3, 2)
        i, j = np.nested_iters(a, [[], [1, 0, 2]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])

        i, j = np.nested_iters(a, [[1, 0, 2], []])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]])

        i, j, k = np.nested_iters(a, [[2, 0], [], [1]])
        vals = []
        for x in i:
            for y in j:
                vals.append([z for z in k])
        assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #19
Source File: test_nditer.py    From Computable with MIT License 6 votes vote down vote up
def test_iter_nested_iters_basic():
    # Test nested iteration basic usage
    a = arange(12).reshape(2, 3, 2)

    i, j = np.nested_iters(a, [[0], [1, 2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]])

    i, j = np.nested_iters(a, [[0, 1], [2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]])

    i, j = np.nested_iters(a, [[0, 2], [1]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #20
Source File: test_nditer.py    From elasticintel with GNU General Public License v3.0 6 votes vote down vote up
def test_iter_nested_iters_broadcast():
    # Test nested iteration with broadcasting
    a = arange(2).reshape(2, 1)
    b = arange(3).reshape(1, 3)

    i, j = np.nested_iters([a, b], [[0], [1]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]]])

    i, j = np.nested_iters([a, b], [[1], [0]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[[0, 0], [1, 0]], [[0, 1], [1, 1]], [[0, 2], [1, 2]]]) 
Example #21
Source File: test_nditer.py    From GraphicDesignPatternByPython with MIT License 6 votes vote down vote up
def test_broadcast(self):
        # Test nested iteration with broadcasting
        a = arange(2).reshape(2, 1)
        b = arange(3).reshape(1, 3)

        i, j = np.nested_iters([a, b], [[0], [1]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]]])

        i, j = np.nested_iters([a, b], [[1], [0]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[[0, 0], [1, 0]], [[0, 1], [1, 1]], [[0, 2], [1, 2]]]) 
Example #22
Source File: test_nditer.py    From Computable with MIT License 6 votes vote down vote up
def test_iter_nested_iters_broadcast():
    # Test nested iteration with broadcasting
    a = arange(2).reshape(2, 1)
    b = arange(3).reshape(1, 3)

    i, j = np.nested_iters([a, b], [[0], [1]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]]])

    i, j = np.nested_iters([a, b], [[1], [0]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[[0, 0], [1, 0]], [[0, 1], [1, 1]], [[0, 2], [1, 2]]]) 
Example #23
Source File: test_nditer.py    From mxnet-lambda with Apache License 2.0 6 votes vote down vote up
def test_iter_nested_iters_broadcast():
    # Test nested iteration with broadcasting
    a = arange(2).reshape(2, 1)
    b = arange(3).reshape(1, 3)

    i, j = np.nested_iters([a, b], [[0], [1]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]]])

    i, j = np.nested_iters([a, b], [[1], [0]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[[0, 0], [1, 0]], [[0, 1], [1, 1]], [[0, 2], [1, 2]]]) 
Example #24
Source File: test_nditer.py    From Computable with MIT License 6 votes vote down vote up
def test_0d_nested_iter():
    a = np.arange(12).reshape(2, 3, 2)
    i, j = np.nested_iters(a, [[], [1, 0, 2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])

    i, j = np.nested_iters(a, [[1, 0, 2], []])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]])

    i, j, k = np.nested_iters(a, [[2, 0], [], [1]])
    vals = []
    for x in i:
        for y in j:
            vals.append([z for z in k])
    assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #25
Source File: test_nditer.py    From elasticintel with GNU General Public License v3.0 6 votes vote down vote up
def test_iter_nested_iters_basic():
    # Test nested iteration basic usage
    a = arange(12).reshape(2, 3, 2)

    i, j = np.nested_iters(a, [[0], [1, 2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]])

    i, j = np.nested_iters(a, [[0, 1], [2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]])

    i, j = np.nested_iters(a, [[0, 2], [1]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #26
Source File: test_nditer.py    From ImageFusion with MIT License 6 votes vote down vote up
def test_0d_nested_iter():
    a = np.arange(12).reshape(2, 3, 2)
    i, j = np.nested_iters(a, [[], [1, 0, 2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])

    i, j = np.nested_iters(a, [[1, 0, 2], []])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]])

    i, j, k = np.nested_iters(a, [[2, 0], [], [1]])
    vals = []
    for x in i:
        for y in j:
            vals.append([z for z in k])
    assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #27
Source File: test_nditer.py    From GraphicDesignPatternByPython with MIT License 6 votes vote down vote up
def test_0d(self):
        a = np.arange(12).reshape(2, 3, 2)
        i, j = np.nested_iters(a, [[], [1, 0, 2]])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])

        i, j = np.nested_iters(a, [[1, 0, 2], []])
        vals = []
        for x in i:
            vals.append([y for y in j])
        assert_equal(vals, [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]])

        i, j, k = np.nested_iters(a, [[2, 0], [], [1]])
        vals = []
        for x in i:
            for y in j:
                vals.append([z for z in k])
        assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #28
Source File: test_nditer.py    From ImageFusion with MIT License 6 votes vote down vote up
def test_iter_nested_iters_broadcast():
    # Test nested iteration with broadcasting
    a = arange(2).reshape(2, 1)
    b = arange(3).reshape(1, 3)

    i, j = np.nested_iters([a, b], [[0], [1]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[[0, 0], [0, 1], [0, 2]], [[1, 0], [1, 1], [1, 2]]])

    i, j = np.nested_iters([a, b], [[1], [0]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[[0, 0], [1, 0]], [[0, 1], [1, 1]], [[0, 2], [1, 2]]]) 
Example #29
Source File: test_nditer.py    From elasticintel with GNU General Public License v3.0 6 votes vote down vote up
def test_0d_nested_iter():
    a = np.arange(12).reshape(2, 3, 2)
    i, j = np.nested_iters(a, [[], [1, 0, 2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]])

    i, j = np.nested_iters(a, [[1, 0, 2], []])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0], [1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11]])

    i, j, k = np.nested_iters(a, [[2, 0], [], [1]])
    vals = []
    for x in i:
        for y in j:
            vals.append([z for z in k])
    assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]]) 
Example #30
Source File: test_nditer.py    From mxnet-lambda with Apache License 2.0 5 votes vote down vote up
def test_iter_nested_iters_reorder():
    # Test nested iteration basic usage
    a = arange(12).reshape(2, 3, 2)

    # In 'K' order (default), it gets reordered
    i, j = np.nested_iters(a, [[0], [2, 1]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2, 3, 4, 5], [6, 7, 8, 9, 10, 11]])

    i, j = np.nested_iters(a, [[1, 0], [2]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1], [2, 3], [4, 5], [6, 7], [8, 9], [10, 11]])

    i, j = np.nested_iters(a, [[2, 0], [1]])
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 2, 4], [1, 3, 5], [6, 8, 10], [7, 9, 11]])

    # In 'C' order, it doesn't
    i, j = np.nested_iters(a, [[0], [2, 1]], order='C')
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 2, 4, 1, 3, 5], [6, 8, 10, 7, 9, 11]])

    i, j = np.nested_iters(a, [[1, 0], [2]], order='C')
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1], [6, 7], [2, 3], [8, 9], [4, 5], [10, 11]])

    i, j = np.nested_iters(a, [[2, 0], [1]], order='C')
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 2, 4], [6, 8, 10], [1, 3, 5], [7, 9, 11]])