MCPcopy Create free account
hub / github.com/numpy/numpy / test_flat

Method test_flat

numpy/matrixlib/tests/test_masked_matrix.py:95–118  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

93 assert_equal(m.mean(axis=1), [[1.5], [3.5]])
94
95 def test_flat(self):
96 # Test that flat can return items even for matrices [#4585, #4615]
97 # test simple access
98 test = masked_array(np.matrix([[1, 2, 3]]), mask=[0, 0, 1])
99 assert_equal(test.flat[1], 2)
100 assert_equal(test.flat[2], masked)
101 assert_(np.all(test.flat[0:2] == test[0, 0:2]))
102 # Test flat on masked_matrices
103 test = masked_array(np.matrix([[1, 2, 3]]), mask=[0, 0, 1])
104 test.flat = masked_array([3, 2, 1], mask=[1, 0, 0])
105 control = masked_array(np.matrix([[3, 2, 1]]), mask=[1, 0, 0])
106 assert_equal(test, control)
107 # Test setting
108 test = masked_array(np.matrix([[1, 2, 3]]), mask=[0, 0, 1])
109 testflat = test.flat
110 testflat[:] = testflat[[2, 1, 0]]
111 assert_equal(test, control)
112 testflat[0] = 9
113 # test that matrices keep the correct shape (#4615)
114 a = masked_array(np.matrix(np.eye(2)), mask=0)
115 b = a.flat
116 b01 = b[:2]
117 assert_equal(b01.data, np.array([[1., 0.]]))
118 assert_equal(b01.mask, np.array([[False, False]]))
119
120 def test_allany_onmatrices(self):
121 x = np.array([[0.13, 0.26, 0.90],

Callers

nothing calls this directly

Calls 3

assert_equalFunction · 0.90
assert_Function · 0.50
allMethod · 0.45

Tested by

no test coverage detected