예제 #1
0
def test_broad_first():
    # Test broadcasting over second axis
    a = np.arange(4) + 10
    b = np.arange(4).reshape(4, 1)
    c = broadcast_first(a, b, add)
    res = a[:, None] + b
    assert_equal(res.shape, c.shape)
    assert_array_almost_equal(c, res)
    res1d = res.ravel()
    c = broadcast_first(b, a, add)
    assert_equal(res1d.shape, c.shape)
    assert_array_almost_equal(c, res1d)
    c = broadcast_first(a, b.ravel(), add)
    assert_equal(res1d.shape, c.shape)
    assert_array_almost_equal(c, res1d)
예제 #2
0
def test_broad_first():
    # Test broadcasting over second axis
    a = np.arange(4) + 10
    b = np.arange(4).reshape(4,1)
    c = broadcast_first(a, b, add)
    res = a[:,None] + b
    assert_equal(res.shape, c.shape)
    assert_array_equal(c, res)
    res1d = res.ravel()
    c = broadcast_first(b, a, add)
    assert_equal(res1d.shape, c.shape)
    assert_array_equal(c, res1d)
    c = broadcast_first(a, b.ravel(), add)
    assert_equal(res1d.shape, c.shape)
    assert_array_equal(c, res1d)