Пример #1
0
    def test_ufunc_out(self):
        from numpypy import array, negative, zeros, sin
        from math import sin as msin
        a = array([[1, 2], [3, 4]])
        c = zeros((2,2,2))
        b = negative(a + a, out=c[1])
        #test for view, and also test that forcing out also forces b
        assert (c[:, :, 1] == [[0, 0], [-4, -8]]).all()
        assert (b == [[-2, -4], [-6, -8]]).all()
        #Test broadcast, type promotion
        b = negative(3, out=a)
        assert (a == -3).all()
        c = zeros((2, 2), dtype=float)
        b = negative(3, out=c)
        assert b.dtype.kind == c.dtype.kind
        assert b.shape == c.shape
        a = array([1, 2])
        b = sin(a, out=c)
        assert(c == [[msin(1), msin(2)]] * 2).all()
        b = sin(a, out=c+c)
        assert (c == b).all()

        #Test shape agreement
        a = zeros((3,4))
        b = zeros((3,5))
        raises(ValueError, 'negative(a, out=b)')
        b = zeros((1,4))
        raises(ValueError, 'negative(a, out=b)')
Пример #2
0
    def test_sin(self):
        import math
        from numpypy import array, sin

        a = array([0, 1, 2, 3, math.pi, math.pi*1.5, math.pi*2])
        b = sin(a)
        for i in range(len(a)):
            assert b[i] == math.sin(a[i])

        a = sin(array([True, False], dtype=bool))
        assert abs(a[0] - sin(1)) < 1e-7 # a[0] will be less precise
        assert a[1] == 0.0
Пример #3
0
 def test_debug_repr(self):
     from numpypy import zeros, sin
     a = zeros(1)
     assert a.__debug_repr__() == 'Array'
     assert (a + a).__debug_repr__() == 'Call2(add, Array, Array)'
     assert (a[::2]).__debug_repr__() == 'Slice(Array)'
     assert (a + 2).__debug_repr__() == 'Call2(add, Array, Scalar)'
     assert (a + a.flat).__debug_repr__() == 'Call2(add, Array, FlatIter(Array))'
     assert sin(a).__debug_repr__() == 'Call1(sin, Array)'
     b = a + a
     b[0] = 3
     assert b.__debug_repr__() == 'Call2(add, forced=Array)'
Пример #4
0
def T_0 (n,k,s):
    if n > 0:
        return np.sin(s.pi*k*s.dz)
    else:
        return 1-k*s.dz
try:
    import numpypy as np
except ImportError:
    import numpy as np

from mediansmooth import *

N = 1000000
#x = np.linspace(0, 2*np.pi, N)
x = np.arange(N) * (2*np.pi / (N - 1))
y = np.sin(x)

#y += 0.5*(2*np.random.random(x.size)-1)

ind2 = mediansmooth_old(y, 100)

print ind2[:20]

try:
    import matplotlib.pyplot as plt
except ImportError:
    pass
else:
    plt.plot(x, y, x, y[ind2])
    plt.show()