Example #1
0
 def test_repeated_input(self):
     length_of_vector = 5
     x = np.arange(length_of_vector)
     out = ix_(x, x)
     assert_equal(out[0].shape, (length_of_vector, 1))
     assert_equal(out[1].shape, (1, length_of_vector))
     # check that input shape is not modified
     assert_equal(x.shape, (length_of_vector,))
 def test_repeated_input(self):
     length_of_vector = 5
     x = np.arange(length_of_vector)
     out = ix_(x, x)
     assert_equal(out[0].shape, (length_of_vector, 1))
     assert_equal(out[1].shape, (1, length_of_vector))
     # check that input shape is not modified
     assert_equal(x.shape, (length_of_vector, ))
Example #3
0
 def test_ix_function(self):
     
     a = array([1,2,3,4])
     b = array([5,6,7])
     c = array([8,9,10,11,12])
     ax,bx,cx = ix_(a,b,c)
     numpy.testing.assert_array_equal(ax, array([[[1]],
                                                 [[2]],
                                                 [[3]],
                                                 [[4]]])) # 4x1x1
     numpy.testing.assert_array_equal(bx, array([[[5],
                                                  [6],
                                                  [7]]])) # 1x3x1
     
     numpy.testing.assert_array_equal(cx, array([[[8,9,10,11,12]]])) # 1x1x5
     
     self.assertEqual(ax.shape, (4,1,1))
     self.assertEqual(bx.shape, (1,3,1))
     self.assertEqual(cx.shape, (1,1,5))
     
     ax_plus_bx = ax + bx
     numpy.testing.assert_array_equal(ax_plus_bx, array([[[6],
                                                          [7],
                                                          [8]],
                                                         [[7],
                                                          [8],
                                                          [9]],
                                                         [[8],
                                                          [9],
                                                          [10]],
                                                         [[9],
                                                          [10],
                                                          [11]]]))
     ax_plus_bx_plus_cx = ax+bx+cx
     numpy.testing.assert_array_equal(ax_plus_bx_plus_cx, array([[[14,15,16,17,18],
                                                                  [15,16,17,18,19],
                                                                  [16,17,18,19,20]],
                                                                 [[15,16,17,18,19],
                                                                  [16,17,18,19,20],
                                                                  [17,18,19,20,21]],
                                                                 [[16,17,18,19,20],
                                                                  [17,18,19,20,21],
                                                                  [18,19,20,21,22]],
                                                                 [[17,18,19,20,21],
                                                                  [18,19,20,21,22],
                                                                  [19,20,21,22,23]]]))