예제 #1
0
    def test_hstack(self):
        import numpypy as np
        a = np.array((1, 2, 3))
        b = np.array((2, 3, 4))
        c = np.hstack((a, b))
        assert np.array_equal(c, [1, 2, 3, 2, 3, 4])

        a = np.array([[1], [2], [3]])
        b = np.array([[2], [3], [4]])
        c = np.hstack((a, b))
        assert np.array_equal(c, [[1, 2],
                                  [2, 3],
                                  [3, 4]])

        for shape1, shape2 in [[(1, 2), (1, 3)],
                               [(4, 2), (4, 3)]]:
            a, b = np.ones(shape1), np.ones(shape2)
            assert np.all(np.hstack((a, b)) ==
                          np.ones((a.shape[0],
                                   a.shape[1] + b.shape[1])))

        #skip("https://bugs.pypy.org/issue1394")
        for shape1, shape2 in [[(2, 3, 4), (2, 7, 4)],
                               [(1, 4, 7), (1, 10, 7)],
                               [(1, 4, 7), (1, 0, 7)],
                               [(1, 0, 7), (1, 0, 7)]]:
            a, b = np.ones(shape1), np.ones(shape2)
            assert np.all(np.hstack((a, b)) ==
                          np.ones((a.shape[0],
                                   a.shape[1] + b.shape[1],
                                   a.shape[2])))
예제 #2
0
    def test_hstack(self):
        import numpypy as np
        a = np.array((1, 2, 3))
        b = np.array((2, 3, 4))
        c = np.hstack((a, b))
        assert np.array_equal(c, [1, 2, 3, 2, 3, 4])

        a = np.array([[1], [2], [3]])
        b = np.array([[2], [3], [4]])
        c = np.hstack((a, b))
        assert np.array_equal(c, [[1, 2],
                                  [2, 3],
                                  [3, 4]])

        for shape1, shape2 in [[(1, 2), (1, 3)],
                               [(4, 2), (4, 3)]]:
            a, b = np.ones(shape1), np.ones(shape2)
            assert np.all(np.hstack((a, b)) ==
                          np.ones((a.shape[0],
                                   a.shape[1] + b.shape[1])))

        #skip("https://bugs.pypy.org/issue1394")
        for shape1, shape2 in [[(2, 3, 4), (2, 7, 4)],
                               [(1, 4, 7), (1, 10, 7)],
                               [(1, 4, 7), (1, 0, 7)],
                               [(1, 0, 7), (1, 0, 7)]]:
            a, b = np.ones(shape1), np.ones(shape2)
            assert np.all(np.hstack((a, b)) ==
                          np.ones((a.shape[0],
                                   a.shape[1] + b.shape[1],
                                   a.shape[2])))
예제 #3
0
def add_bias(A):
    return np.hstack(( np.ones((A.shape[0],1)), A )) # Add 1 as bias.
예제 #4
0
def add_bias(A):
    return np.hstack((np.ones((A.shape[0], 1)), A))  # Add 1 as bias.