Esempio n. 1
0
def test_kron_matrix():
    # 2018-04-29: moved here from core.tests.test_shape_base.
    a = np.ones([2, 2])
    m = np.asmatrix(a)
    assert_equal(type(np.kron(a, a)), np.ndarray)
    assert_equal(type(np.kron(m, m)), np.matrix)
    assert_equal(type(np.kron(a, m)), np.matrix)
    assert_equal(type(np.kron(m, a)), np.matrix)
Esempio n. 2
0
def test_fancy_indexing():
    # The matrix class messes with the shape. While this is always
    # weird (getitem is not used, it does not have setitem nor knows
    # about fancy indexing), this tests gh-3110
    # 2018-04-29: moved here from core.tests.test_index.
    m = np.matrix([[1, 2], [3, 4]])

    assert_(isinstance(m[[0, 1, 0], :], np.matrix))

    # gh-3110. Note the transpose currently because matrices do *not*
    # support dimension fixing for fancy indexing correctly.
    x = np.asmatrix(np.arange(50).reshape(5, 10))
    assert_equal(x[:2, np.array(-1)], x[:2, -1].T)
Esempio n. 3
0
 def test_list_indexing(self):
     A = np.arange(6)
     A.shape = (3, 2)
     x = asmatrix(A)
     assert_array_equal(x[:, [1, 0]], x[:, ::-1])
     assert_array_equal(x[[2, 1, 0], :], x[::-1, :])
Esempio n. 4
0
 def test_matrix_std_argmax(self):
     # Ticket #83
     x = np.asmatrix(np.random.uniform(0, 1, (3, 3)))
     assert_equal(x.std().shape, ())
     assert_equal(x.argmax().shape, ())
Esempio n. 5
0
 def test_boolean_indexing(self):
     A = np.arange(6)
     A.shape = (3, 2)
     x = asmatrix(A)
     assert_array_equal(x[:, np.array([True, False])], x[:, 0])
     assert_array_equal(x[np.array([True, False, False]), :], x[0, :])
Esempio n. 6
0
 def test_row_column_indexing(self):
     x = asmatrix(np.eye(2))
     assert_array_equal(x[0, :], [[1, 0]])
     assert_array_equal(x[1, :], [[0, 1]])
     assert_array_equal(x[:, 0], [[1], [0]])
     assert_array_equal(x[:, 1], [[0], [1]])
Esempio n. 7
0
 def test_scalar_indexing(self):
     x = asmatrix(np.zeros((3, 2), float))
     assert_equal(x[0, 0], x[0][0])
Esempio n. 8
0
 def test_basic(self):
     x = asmatrix(np.zeros((3, 2), float))
     y = np.zeros((3, 1), float)
     y[:, 0] = [0.8, 0.2, 0.3]
     x[:, 1] = y > 0.5
     assert_equal(x, [[0, 1], [0, 0], [0, 0]])
Esempio n. 9
0
 def test_asmatrix(self):
     A = np.arange(100).reshape(10, 10)
     mA = asmatrix(A)
     A[0, 0] = -10
     assert_(A[0, 0] == mA[0, 0])