def test_multidim_setslice(self): from _numpypy import zeros, ones a = zeros((3, 3)) b = ones((3, 3)) a[:, 1:3] = b[:, 1:3] assert (a == [[0, 1, 1], [0, 1, 1], [0, 1, 1]]).all() a = zeros((3, 3)) b = ones((3, 3)) a[:, ::2] = b[:, ::2] assert (a == [[1, 0, 1], [1, 0, 1], [1, 0, 1]]).all()
def test_ones_long(self): from _numpypy import ones, int64 a = ones(10, dtype=long) for i in range(10): assert isinstance(a[i], int64) assert a[1] == 1
def test_ones(self): from _numpypy import ones a = ones(3) assert len(a) == 3 assert a[0] == 1 raises(IndexError, "a[3]") a[2] = 4 assert a[2] == 4
def test_where(self): from _numpypy import where, ones, zeros, array a = [1, 2, 3, 0, -3] a = where(array(a) > 0, ones(5), zeros(5)) assert (a == [1, 1, 1, 0, 0]).all()
def test_flatiter_varray(self): from _numpypy import ones a = ones((2, 2)) assert list(((a + a).flat)) == [2, 2, 2, 2]
def test_broadcast_call2(self): from _numpypy import zeros, ones a = zeros((4, 1, 5)) b = ones((4, 3, 5)) b[:] = (a + a) assert (b == zeros((4, 3, 5))).all()
def test_broadcast_setslice(self): from _numpypy import zeros, ones a = zeros((10, 10)) b = ones(10) a[:, :] = b assert a[3, 5] == 1
def test_multidim_ones(self): from _numpypy import ones a = ones((1, 2, 3)) assert a[0, 1, 2] == 1.0
def test_ones_long(self): from _numpypy import ones, longlong a = ones(10, dtype=long) for i in range(10): assert isinstance(a[i], longlong) assert a[1] == 1
def test_ones_bool(self): from _numpypy import ones, True_ a = ones(10, dtype=bool) for i in range(10): assert a[i] is True_
def test_where_invalidates(self): from _numpypy import where, ones, zeros, array a = array([1, 2, 3, 0, -3]) b = where(a > 0, ones(5), zeros(5)) a[0] = 0 assert (b == [1, 1, 1, 0, 0]).all()