Python numpy.nested_iters() 使用实例

The following are code examples for showing how to use . They are extracted from open source Python projects. You can vote up the examples you like or vote down the exmaples you don’t like. You can also save this page to your account.

Example 1

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 2

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 3

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 4

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 5

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 6

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 7

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

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 9

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 10

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 11

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 12

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 13

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 14

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 15

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 16

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 17

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 18

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 19

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

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

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 22

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]]) 

Example 23

def test_iter_nested_iters_flip_axes():
    # Test nested iteration with negative axes
    a = arange(12).reshape(2, 3, 2)[::-1, ::-1, ::-1]

    # In 'K' order (default), the axes all get flipped
    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]])

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

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

    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, [[11, 9, 7], [10, 8, 6], [5, 3, 1], [4, 2, 0]]) 

Example 24

def test_iter_nested_iters_dtype_copy():
    # Test nested iteration with a copy to change dtype

    # copy
    a = arange(6, dtype='i4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readonly', 'copy'],
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2], [3, 4, 5]])
    vals = None

    # updateifcopy
    a = arange(6, dtype='f4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readwrite', 'updateifcopy'],
                        casting='same_kind',
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    for x in i:
        for y in j:
            y[...] += 1
    assert_equal(a, [[0, 1, 2], [3, 4, 5]])
    i, j, x, y = (None,)*4  # force the updateifcopy
    assert_equal(a, [[1, 2, 3], [4, 5, 6]]) 

Example 25

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]]) 

Example 26

def test_iter_nested_iters_flip_axes():
    # Test nested iteration with negative axes
    a = arange(12).reshape(2, 3, 2)[::-1, ::-1, ::-1]

    # In 'K' order (default), the axes all get flipped
    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]])

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

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

    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, [[11, 9, 7], [10, 8, 6], [5, 3, 1], [4, 2, 0]]) 

Example 27

def test_iter_nested_iters_dtype_copy():
    # Test nested iteration with a copy to change dtype

    # copy
    a = arange(6, dtype='i4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readonly', 'copy'],
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2], [3, 4, 5]])
    vals = None

    # updateifcopy
    a = arange(6, dtype='f4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readwrite', 'updateifcopy'],
                        casting='same_kind',
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    for x in i:
        for y in j:
            y[...] += 1
    assert_equal(a, [[0, 1, 2], [3, 4, 5]])
    i, j, x, y = (None,)*4  # force the updateifcopy
    assert_equal(a, [[1, 2, 3], [4, 5, 6]]) 

Example 28

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]]) 

Example 29

def test_iter_nested_iters_flip_axes():
    # Test nested iteration with negative axes
    a = arange(12).reshape(2, 3, 2)[::-1, ::-1, ::-1]

    # In 'K' order (default), the axes all get flipped
    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]])

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

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

    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, [[11, 9, 7], [10, 8, 6], [5, 3, 1], [4, 2, 0]]) 

Example 30

def test_iter_nested_iters_dtype_copy():
    # Test nested iteration with a copy to change dtype

    # copy
    a = arange(6, dtype='i4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readonly', 'copy'],
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2], [3, 4, 5]])
    vals = None

    # updateifcopy
    a = arange(6, dtype='f4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readwrite', 'updateifcopy'],
                        casting='same_kind',
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    for x in i:
        for y in j:
            y[...] += 1
    assert_equal(a, [[0, 1, 2], [3, 4, 5]])
    i, j, x, y = (None,)*4  # force the updateifcopy
    assert_equal(a, [[1, 2, 3], [4, 5, 6]]) 

Example 31

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]]) 

Example 32

def test_iter_nested_iters_flip_axes():
    # Test nested iteration with negative axes
    a = arange(12).reshape(2, 3, 2)[::-1, ::-1, ::-1]

    # In 'K' order (default), the axes all get flipped
    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]])

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

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

    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, [[11, 9, 7], [10, 8, 6], [5, 3, 1], [4, 2, 0]]) 

Example 33

def test_iter_nested_iters_dtype_copy():
    # Test nested iteration with a copy to change dtype

    # copy
    a = arange(6, dtype='i4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readonly', 'copy'],
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2], [3, 4, 5]])
    vals = None

    # updateifcopy
    a = arange(6, dtype='f4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readwrite', 'updateifcopy'],
                        casting='same_kind',
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    for x in i:
        for y in j:
            y[...] += 1
    assert_equal(a, [[0, 1, 2], [3, 4, 5]])
    i, j, x, y = (None,)*4  # force the updateifcopy
    assert_equal(a, [[1, 2, 3], [4, 5, 6]]) 

Example 34

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]]) 

Example 35

def test_iter_nested_iters_flip_axes():
    # Test nested iteration with negative axes
    a = arange(12).reshape(2, 3, 2)[::-1, ::-1, ::-1]

    # In 'K' order (default), the axes all get flipped
    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]])

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

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

    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, [[11, 9, 7], [10, 8, 6], [5, 3, 1], [4, 2, 0]]) 

Example 36

def test_iter_nested_iters_dtype_copy():
    # Test nested iteration with a copy to change dtype

    # copy
    a = arange(6, dtype='i4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readonly', 'copy'],
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2], [3, 4, 5]])
    vals = None

    # updateifcopy
    a = arange(6, dtype='f4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readwrite', 'updateifcopy'],
                        casting='same_kind',
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    for x in i:
        for y in j:
            y[...] += 1
    assert_equal(a, [[0, 1, 2], [3, 4, 5]])
    i, j, x, y = (None,)*4  # force the updateifcopy
    assert_equal(a, [[1, 2, 3], [4, 5, 6]]) 

Example 37

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]]) 

Example 38

def test_iter_nested_iters_flip_axes():
    # Test nested iteration with negative axes
    a = arange(12).reshape(2, 3, 2)[::-1, ::-1, ::-1]

    # In 'K' order (default), the axes all get flipped
    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]])

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

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

    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, [[11, 9, 7], [10, 8, 6], [5, 3, 1], [4, 2, 0]]) 

Example 39

def test_iter_nested_iters_dtype_copy():
    # Test nested iteration with a copy to change dtype

    # copy
    a = arange(6, dtype='i4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readonly', 'copy'],
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2], [3, 4, 5]])
    vals = None

    # updateifcopy
    a = arange(6, dtype='f4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readwrite', 'updateifcopy'],
                        casting='same_kind',
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    for x in i:
        for y in j:
            y[...] += 1
    assert_equal(a, [[0, 1, 2], [3, 4, 5]])
    i, j, x, y = (None,)*4  # force the updateifcopy
    assert_equal(a, [[1, 2, 3], [4, 5, 6]]) 

Example 40

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]]) 

Example 41

def test_iter_nested_iters_flip_axes():
    # Test nested iteration with negative axes
    a = arange(12).reshape(2, 3, 2)[::-1, ::-1, ::-1]

    # In 'K' order (default), the axes all get flipped
    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]])

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

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

    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, [[11, 9, 7], [10, 8, 6], [5, 3, 1], [4, 2, 0]]) 

Example 42

def test_iter_nested_iters_dtype_copy():
    # Test nested iteration with a copy to change dtype

    # copy
    a = arange(6, dtype='i4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readonly', 'copy'],
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    vals = []
    for x in i:
        vals.append([y for y in j])
    assert_equal(vals, [[0, 1, 2], [3, 4, 5]])
    vals = None

    # updateifcopy
    a = arange(6, dtype='f4').reshape(2, 3)
    i, j = np.nested_iters(a, [[0], [1]],
                        op_flags=['readwrite', 'updateifcopy'],
                        casting='same_kind',
                        op_dtypes='f8')
    assert_equal(j[0].dtype, np.dtype('f8'))
    for x in i:
        for y in j:
            y[...] += 1
    assert_equal(a, [[0, 1, 2], [3, 4, 5]])
    i, j, x, y = (None,)*4  # force the updateifcopy
    assert_equal(a, [[1, 2, 3], [4, 5, 6]]) 
点赞