MCPcopy Index your code
hub / github.com/numpy/numpy / test_stack_nd

Method test_stack_nd

numpy/ma/tests/test_extras.py:1904–1945  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1902 assert_array_equal(b.mask, c[:, 1].mask)
1903
1904 def test_stack_nd(self):
1905 # 2D
1906 shp = (3, 2)
1907 d1 = np.random.randint(0, 10, shp)
1908 d2 = np.random.randint(0, 10, shp)
1909 m1 = np.random.randint(0, 2, shp).astype(bool)
1910 m2 = np.random.randint(0, 2, shp).astype(bool)
1911 a1 = masked_array(d1, mask=m1)
1912 a2 = masked_array(d2, mask=m2)
1913
1914 c = stack([a1, a2], axis=0)
1915 c_shp = (2,) + shp
1916 assert_equal(c.shape, c_shp)
1917 assert_array_equal(a1.mask, c[0].mask)
1918 assert_array_equal(a2.mask, c[1].mask)
1919
1920 c = stack([a1, a2], axis=-1)
1921 c_shp = shp + (2,)
1922 assert_equal(c.shape, c_shp)
1923 assert_array_equal(a1.mask, c[..., 0].mask)
1924 assert_array_equal(a2.mask, c[..., 1].mask)
1925
1926 # 4D
1927 shp = (3, 2, 4, 5,)
1928 d1 = np.random.randint(0, 10, shp)
1929 d2 = np.random.randint(0, 10, shp)
1930 m1 = np.random.randint(0, 2, shp).astype(bool)
1931 m2 = np.random.randint(0, 2, shp).astype(bool)
1932 a1 = masked_array(d1, mask=m1)
1933 a2 = masked_array(d2, mask=m2)
1934
1935 c = stack([a1, a2], axis=0)
1936 c_shp = (2,) + shp
1937 assert_equal(c.shape, c_shp)
1938 assert_array_equal(a1.mask, c[0].mask)
1939 assert_array_equal(a2.mask, c[1].mask)
1940
1941 c = stack([a1, a2], axis=-1)
1942 c_shp = shp + (2,)
1943 assert_equal(c.shape, c_shp)
1944 assert_array_equal(a1.mask, c[..., 0].mask)
1945 assert_array_equal(a2.mask, c[..., 1].mask)

Callers

nothing calls this directly

Calls 4

assert_equalFunction · 0.90
assert_array_equalFunction · 0.90
stackFunction · 0.85
astypeMethod · 0.80

Tested by

no test coverage detected