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

Method test_stack_nd

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

Source from the content-addressed store, hash-verified

1827 assert_array_equal(b.mask, c[:, 1].mask)
1828
1829 def test_stack_nd(self):
1830 # 2D
1831 shp = (3, 2)
1832 d1 = np.random.randint(0, 10, shp)
1833 d2 = np.random.randint(0, 10, shp)
1834 m1 = np.random.randint(0, 2, shp).astype(bool)
1835 m2 = np.random.randint(0, 2, shp).astype(bool)
1836 a1 = masked_array(d1, mask=m1)
1837 a2 = masked_array(d2, mask=m2)
1838
1839 c = stack([a1, a2], axis=0)
1840 c_shp = (2,) + shp
1841 assert_equal(c.shape, c_shp)
1842 assert_array_equal(a1.mask, c[0].mask)
1843 assert_array_equal(a2.mask, c[1].mask)
1844
1845 c = stack([a1, a2], axis=-1)
1846 c_shp = shp + (2,)
1847 assert_equal(c.shape, c_shp)
1848 assert_array_equal(a1.mask, c[..., 0].mask)
1849 assert_array_equal(a2.mask, c[..., 1].mask)
1850
1851 # 4D
1852 shp = (3, 2, 4, 5,)
1853 d1 = np.random.randint(0, 10, shp)
1854 d2 = np.random.randint(0, 10, shp)
1855 m1 = np.random.randint(0, 2, shp).astype(bool)
1856 m2 = np.random.randint(0, 2, shp).astype(bool)
1857 a1 = masked_array(d1, mask=m1)
1858 a2 = masked_array(d2, mask=m2)
1859
1860 c = stack([a1, a2], axis=0)
1861 c_shp = (2,) + shp
1862 assert_equal(c.shape, c_shp)
1863 assert_array_equal(a1.mask, c[0].mask)
1864 assert_array_equal(a2.mask, c[1].mask)
1865
1866 c = stack([a1, a2], axis=-1)
1867 c_shp = shp + (2,)
1868 assert_equal(c.shape, c_shp)
1869 assert_array_equal(a1.mask, c[..., 0].mask)
1870 assert_array_equal(a2.mask, c[..., 1].mask)

Callers

nothing calls this directly

Calls 4

assert_equalFunction · 0.90
assert_array_equalFunction · 0.90
astypeMethod · 0.80
stackFunction · 0.50

Tested by

no test coverage detected