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

Method test_ndim

numpy/lib/tests/test_function_base.py:2128–2163  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

2126 assert_almost_equal(r, 1, 7)
2127
2128 def test_ndim(self):
2129 x = np.linspace(0, 1, 3)
2130 y = np.linspace(0, 2, 8)
2131 z = np.linspace(0, 3, 13)
2132
2133 wx = np.ones_like(x) * (x[1] - x[0])
2134 wx[0] /= 2
2135 wx[-1] /= 2
2136 wy = np.ones_like(y) * (y[1] - y[0])
2137 wy[0] /= 2
2138 wy[-1] /= 2
2139 wz = np.ones_like(z) * (z[1] - z[0])
2140 wz[0] /= 2
2141 wz[-1] /= 2
2142
2143 q = x[:, None, None] + y[None,:, None] + z[None, None,:]
2144
2145 qx = (q * wx[:, None, None]).sum(axis=0)
2146 qy = (q * wy[None, :, None]).sum(axis=1)
2147 qz = (q * wz[None, None, :]).sum(axis=2)
2148
2149 # n-d `x`
2150 r = trapz(q, x=x[:, None, None], axis=0)
2151 assert_almost_equal(r, qx)
2152 r = trapz(q, x=y[None,:, None], axis=1)
2153 assert_almost_equal(r, qy)
2154 r = trapz(q, x=z[None, None,:], axis=2)
2155 assert_almost_equal(r, qz)
2156
2157 # 1-d `x`
2158 r = trapz(q, x=x, axis=0)
2159 assert_almost_equal(r, qx)
2160 r = trapz(q, x=y, axis=1)
2161 assert_almost_equal(r, qy)
2162 r = trapz(q, x=z, axis=2)
2163 assert_almost_equal(r, qz)
2164
2165 def test_masked(self):
2166 # Testing that masked arrays behave as if the function is 0 where

Callers

nothing calls this directly

Calls 4

trapzFunction · 0.90
assert_almost_equalFunction · 0.90
linspaceMethod · 0.80
sumMethod · 0.45

Tested by

no test coverage detected