numpy.empty_like

Here are the examples of the python api numpy.empty_like taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

199 Examples 7

Example 1

Project: chainer
Source File: hierarchical_softmax.py
View license
    def backward_cpu(self, inputs, grad_outputs):
        x, t, W = inputs
        gloss, = grad_outputs
        gx = numpy.empty_like(x)
        gW = numpy.zeros_like(W)
        for i, (ix, it) in enumerate(six.moves.zip(x, t)):
            gx[i] = self._backward_cpu_one(ix, it, W, gloss, gW)
        return gx, None, gW

Example 2

Project: xarray
Source File: memory.py
View license
    def prepare_variable(self, k, v, check_encoding=False):
        new_var = Variable(v.dims, np.empty_like(v), v.attrs)
        # we copy the variable and stuff all encodings in the
        # attributes to imitate what happens when writing to disk.
        new_var.attrs.update(v.encoding)
        self._variables[k] = new_var
        return new_var, v.data

Example 3

Project: xarray
Source File: common.py
View license
def _full_like_dataarray(arr, keep_attrs=False, fill_value=None):
    """empty DataArray"""
    from .dataarray import DataArray

    attrs = arr.attrs if keep_attrs else {}

    if fill_value is None:
        values = np.empty_like(arr)
    elif fill_value is True:
        dtype, fill_value = _maybe_promote(arr.dtype)
        values = np.full_like(arr, fill_value=fill_value, dtype=dtype)
    else:
        dtype, _ = _maybe_promote(np.array(fill_value).dtype)
        values = np.full_like(arr, fill_value=fill_value, dtype=dtype)

    return DataArray(values, dims=arr.dims, coords=arr.coords, attrs=attrs)

Example 4

Project: lfd
Source File: registration.py
View license
    def transform_hmats(self, hmat_mAD):
        """
        Transform (D+1) x (D+1) homogenius matrices
        """
        hmat_mGD = np.empty_like(hmat_mAD)
        hmat_mGD[:,:3,3] = self.transform_points(hmat_mAD[:,:3,3])
        hmat_mGD[:,:3,:3] = self.transform_bases(hmat_mAD[:,:3,3], hmat_mAD[:,:3,:3])
        hmat_mGD[:,3,:] = np.array([0,0,0,1])
        return hmat_mGD

Example 5

Project: lfd
Source File: tps_registration.py
View license
def rgb2xyz(rgb):
    """
    r,g,b ranges from 0 to 1
    http://en.wikipedia.org/wiki/SRGB_color_space
    http://en.wikipedia.org/wiki/CIE_XYZ
    """
    rgb_linear = np.empty_like(rgb) # copy rgb so that the original rgb is not modified
    
    cond = rgb > 0.04045
    rgb_linear[cond] = np.power((rgb[cond] + 0.055) / 1.055, 2.4)
    rgb_linear[~cond] = rgb[~cond] / 12.92
    
    rgb_to_xyz = np.array([[0.412453, 0.357580, 0.180423],
                           [0.212671, 0.715160, 0.072169],
                           [0.019334, 0.119193, 0.950227]])
    xyz = rgb_linear.dot(rgb_to_xyz.T)
    return xyz

Example 6

Project: lfd
Source File: transformation.py
View license
    def transform_hmats(self, hmat_mAD):
        """
        Transform (D+1) x (D+1) homogenius matrices
        """
        hmat_mGD = np.empty_like(hmat_mAD)
        hmat_mGD[:,:3,3] = self.transform_points(hmat_mAD[:,:3,3])
        hmat_mGD[:,:3,:3] = self.transform_bases(hmat_mAD[:,:3,3], hmat_mAD[:,:3,:3])
        hmat_mGD[:,3,:] = np.array([0,0,0,1])
        return hmat_mGD

Example 7

Project: lfd
Source File: transformations.py
View license
    def transform_hmats(self, hmat_mAD):
        """
        Transform (D+1) x (D+1) homogenius matrices
        """
        hmat_mGD = np.empty_like(hmat_mAD)
        hmat_mGD[:,:3,3] = self.transform_points(hmat_mAD[:,:3,3])
        hmat_mGD[:,:3,:3] = self.transform_bases(hmat_mAD[:,:3,3], hmat_mAD[:,:3,:3])
        hmat_mGD[:,3,:] = np.array([0,0,0,1])
        return hmat_mGD

Example 8

Project: scikit-image
Source File: collection.py
View license
    def reload(self, n=None):
        """Clear the image cache.

        Parameters
        ----------
        n : None or int
            Clear the cache for this image only. By default, the
            entire cache is erased.

        """
        self.data = np.empty_like(self.data)

Example 9

Project: scipy
Source File: _bvp.py
View license
def stacked_matmul(a, b):
    """Stacked matrix multiply: out[i,:,:] = np.dot(a[i,:,:], b[i,:,:]).

    In our case a[i, :, :] and b[i, :, :] are always square.
    """
    # Empirical optimization. Use outer Python loop and BLAS for large
    # matrices, otherwise use a single einsum call.
    if a.shape[1] > 50:
        out = np.empty_like(a)
        for i in range(a.shape[0]):
            out[i] = np.dot(a[i], b[i])
        return out
    else:
        return np.einsum('...ij,...jk->...ik', a, b)

Example 10

Project: scipy
Source File: _decomp_qz.py
View license
def _lhp(x, y):
    out = np.empty_like(x, dtype=bool)
    nonzero = (y != 0)
    # handles (x, y) = (0, 0) too
    out[~nonzero] = False
    out[nonzero] = (np.real(x[nonzero]/y[nonzero]) < 0.0)
    return out

Example 11

Project: scipy
Source File: _decomp_qz.py
View license
def _rhp(x, y):
    out = np.empty_like(x, dtype=bool)
    nonzero = (y != 0)
    # handles (x, y) = (0, 0) too
    out[~nonzero] = False
    out[nonzero] = (np.real(x[nonzero]/y[nonzero]) > 0.0)
    return out

Example 12

Project: scipy
Source File: _decomp_qz.py
View license
def _iuc(x, y):
    out = np.empty_like(x, dtype=bool)
    nonzero = (y != 0)
    # handles (x, y) = (0, 0) too
    out[~nonzero] = False
    out[nonzero] = (abs(x[nonzero]/y[nonzero]) < 1.0)
    return out

Example 13

Project: scipy
Source File: _decomp_qz.py
View license
def _ouc(x, y):
    out = np.empty_like(x, dtype=bool)
    xzero = (x == 0)
    yzero = (y == 0)
    out[xzero & yzero] = False
    out[~xzero & yzero] = True
    out[~yzero] = (abs(x[~yzero]/y[~yzero]) > 1.0)
    return out

Example 14

Project: sfepy
Source File: linear_elastic_iga.py
View license
def get_ebcs(ts, coors, **kwargs):
    import numpy as nm

    aux = nm.empty_like(coors[:, 1:])
    aux[:, 0] = 0.1 * coors[:, 1]
    aux[:, 1] = -0.05 + 0.03 * nm.sin(coors[:, 1] * 5 * nm.pi)

    return aux.T.flat

Example 15

Project: sfepy
Source File: terms_hyperelastic_base.py
View license
    def compute_stress(self, mat, family_data, **kwargs):
        out = nm.empty_like(family_data.green_strain)

        get = family_data.get
        fargs = [get(name, msg_if_none=_msg_missing_data)
                 for name in self.family_data_names]

        self.stress_function(out, mat, *fargs, **kwargs)

        return out

Example 16

Project: GPy
Source File: hmc.py
View license
    def __init__(self, model, M=None,stepsize=1e-1):
        self.model = model
        self.stepsize = stepsize
        self.p = np.empty_like(model.optimizer_array.copy())
        if M is None:
            self.M = np.eye(self.p.size)
        else:
            self.M = M
        self.Minv = np.linalg.inv(self.M)

Example 17

Project: pyscf
Source File: _ccsd.py
View license
def make_0213(v1, v2, alpha=1, beta=1, out=None):
    assert(v1.flags.c_contiguous)
    assert(v2.flags.c_contiguous)
    if out is None:
        out = numpy.empty_like(v1)
    else:
        out = numpy.ndarray(v1.shape, buffer=out)
    count, m = v1.shape[:2]
    libcc.CCmake_0213(out.ctypes.data_as(ctypes.c_void_p),
                      v1.ctypes.data_as(ctypes.c_void_p),
                      v2.ctypes.data_as(ctypes.c_void_p),
                      ctypes.c_int(count), ctypes.c_int(m),
                      ctypes.c_double(alpha), ctypes.c_double(beta))
    return out

Example 18

Project: pyscf
Source File: _ccsd.py
View license
def make_0132(v1, v2, alpha=1, beta=1, out=None):
    assert(v1.flags.c_contiguous)
    assert(v2.flags.c_contiguous)
    if out is None:
        out = numpy.empty_like(v1)
    else:
        out = numpy.ndarray(v1.shape, buffer=out)
    count = v1.shape[0] * v1.shape[1]
    m = v1.shape[2]
    libcc.CCmake_021(out.ctypes.data_as(ctypes.c_void_p),
                     v1.ctypes.data_as(ctypes.c_void_p),
                     v2.ctypes.data_as(ctypes.c_void_p),
                     ctypes.c_int(count), ctypes.c_int(m),
                     ctypes.c_double(alpha), ctypes.c_double(beta))
    return out

Example 19

Project: pyscf
Source File: _ccsd.py
View license
def make_021(v1, v2, alpha=1, beta=1, out=None):
    assert(v1.flags.c_contiguous)
    assert(v2.flags.c_contiguous)
    if out is None:
        out = numpy.empty_like(v1)
    else:
        out = numpy.ndarray(v1.shape, buffer=out)
    count, m = v1.shape[:2]
    libcc.CCmake_021(out.ctypes.data_as(ctypes.c_void_p),
                     v1.ctypes.data_as(ctypes.c_void_p),
                     v2.ctypes.data_as(ctypes.c_void_p),
                     ctypes.c_int(count), ctypes.c_int(m),
                     ctypes.c_double(alpha), ctypes.c_double(beta))
    return out

Example 20

Project: pyscf
Source File: _ccsd.py
View license
def sum021(v1, out=None):
    if out is None:
        out = numpy.empty_like(v1)
    else:
        out = numpy.ndarray(v1.shape, buffer=out)
    count, m = v1.shape[:2]
    libcc.CCsum021(out.ctypes.data_as(ctypes.c_void_p),
                   v1.ctypes.data_as(ctypes.c_void_p),
                   v1.ctypes.data_as(ctypes.c_void_p),
                   ctypes.c_int(count), ctypes.c_int(m))
    return out

Example 21

Project: pyscf
Source File: cistring.py
View license
def reform_linkstr_index(link_index):
    '''Compress the (a, i) pair index in linkstr_index to a lower triangular
    index, to match the 4-fold symmetry of integrals.
    '''
    link_new = numpy.empty_like(link_index)
    for k, tab in enumerate(link_index):
        for j, (a, i, str1, sign) in enumerate(tab):
            if a > i:
                ai = a*(a+1)//2+i
            else:
                ai = i*(i+1)//2+a
            link_new[k,j] = (ai,0,str1,sign)
    return link_new

Example 22

Project: pyscf
Source File: test_ecp.py
View license
    def test_gauss_chebyshev(self):
        rs0, ws0 = radi.gauss_chebyshev(99)
        rs = numpy.empty_like(rs0)
        ws = numpy.empty_like(ws0)
        libecp.ECPgauss_chebyshev(rs.ctypes.data_as(ctypes.c_void_p),
                                  ws.ctypes.data_as(ctypes.c_void_p),
                                  ctypes.c_int(99))
        self.assertTrue(numpy.allclose(rs0, rs))
        self.assertTrue(numpy.allclose(ws0, ws))

Example 23

Project: pyscf
Source File: test_ecp.py
View license
    def test_type2_rad_part(self):
        rc = .8712
        rs, ws = radi.gauss_chebyshev(99)
        def type2_facs_rad(ish, lc):
            facs0 = facs_rad(mol, ish, lc, rc, rs).transpose(0,2,1).copy()
            facs1 = numpy.empty_like(facs0)
            libecp.type2_facs_rad(facs1.ctypes.data_as(ctypes.c_void_p),
                                  ctypes.c_int(ish), ctypes.c_int(lc),
                                  ctypes.c_double(rc),
                                  rs.ctypes.data_as(ctypes.c_void_p),
                                  ctypes.c_int(len(rs)), ctypes.c_int(1),
                                  mol._atm.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(mol.natm),
                                  mol._bas.ctypes.data_as(ctypes.c_void_p), ctypes.c_int(mol.nbas),
                                  mol._env.ctypes.data_as(ctypes.c_void_p))
            self.assertTrue(numpy.allclose(facs0, facs1))
        for ish in range(mol.nbas):
            for lc in range(5):
                type2_facs_rad(ish, lc)

Example 24

Project: pyscf
Source File: rhf_nmr.py
View license
def solve_mo1(mo_energy, mo_occ, h1, s1):
    '''uncoupled equation'''
    e_a = mo_energy[mo_occ==0]
    e_i = mo_energy[mo_occ>0]
    e_ai = 1 / (e_a.reshape(-1,1) - e_i)

    hs = h1 - s1 * e_i

    mo10 = numpy.empty_like(hs)
    mo10[:,mo_occ==0,:] = -hs[:,mo_occ==0,:] * e_ai
    mo10[:,mo_occ>0,:] = -s1[:,mo_occ>0,:] * .5

    e_ji = e_i.reshape(-1,1) - e_i
    mo_e10 = hs[:,mo_occ>0,:] + mo10[:,mo_occ>0,:] * e_ji
    return mo10, mo_e10

Example 25

Project: peregrine
Source File: short_set.py
View license
def sagnac(gps_r, tof):
    # Apply Sagnac correction (reference frame rotation during signal time of flight)
    wEtau = gps.omegae_dot * tof # Rotation of Earth during time of flight in radians.
    gps_r_sagnac = np.empty_like(gps_r)
    gps_r_sagnac[0] = gps_r[0] + wEtau * gps_r[1];
    gps_r_sagnac[1] = gps_r[1] - wEtau * gps_r[0];
    gps_r_sagnac[2] = gps_r[2];
    return gps_r_sagnac

Example 26

Project: westpa
Source File: accumulator.py
View license
    def average(self):
        valid = (self.count > 0)
        avg = numpy.empty_like(self.sum)
        avg[valid] = self.sum[valid] / self.weight[valid]
        avg[~valid] = self.mask_value
        return avg

Example 27

Project: westpa
Source File: accumulator.py
View license
    def std(self):
        valid = (self.count > 0)
        vavg = self.average()[valid]
        std = numpy.empty_like(self.sqsum)
        std[valid] = (self.sqsum[valid] / self.weight[valid] - vavg*vavg)**0.5
        std[~valid] = self.mask_value
        return std

Example 28

Project: pdnn
Source File: __init__.py
View license
def shuffle_across_partitions(feature_list, label_list):
    '''
    Randomly shuffles features and labels in the same order across partitions.
    '''
    total = sum(len(x) for x in feature_list)
    n = len(feature_list[0])    # Partition size
    buffer = numpy.empty_like(feature_list[0][0])
    seed = 18877
    numpy.random.seed(seed)
    for i in xrange(total - 1, 0, -1):
        j = numpy.random.randint(i + 1)
        buffer[:] = feature_list[i / n][i % n]
        feature_list[i / n][i % n] = feature_list[j / n][j % n]
        feature_list[j / n][j % n] = buffer
        label_list[i / n][i % n], label_list[j / n][j % n] = \
            label_list[j / n][j % n], label_list[i / n][i % n]

Example 29

Project: chempy
Source File: _eqsys.py
View license
    def __init__(self, eqsys, init_concs, varied):
        self.eqsys = eqsys
        self.all_inits, self.varied_keys = self.eqsys.per_substance_varied(init_concs, varied)
        self.conc = np.empty_like(self.all_inits)
        for k, v in self.attrs.items():
            setattr(self, k, np.zeros(self.all_inits.shape[:-1], dtype=v))

Example 30

Project: pyvision
Source File: v1like.py
View license
def opp_convert(arr):
    #assert(arr.min()>=0 and arr.max()<=1)
    out = np.empty_like(arr)

    # red-green
    out[:,:,0] = arr[:,:,0] - arr[:,:,1]
    # blue-yellow
    out[:,:,1] = arr[:,:,2] - arr[:,:,[0,1]].min(2)
    # intensity
    out[:,:,2] = arr.max(2)

    return out

Example 31

Project: pyvision
Source File: v1like.py
View license
def rg2_convert(arr):
    #assert(arr.min()>=0 and arr.max()<=1)

    out = np.empty_like(arr[:,:,[0,1]])

    red = arr[:,:,0]
    green = arr[:,:,1]
    #blue = arr[:,:,2]
    intensity = arr.mean(2)

    lowi = intensity < 0.1*intensity.max()
    arr[lowi] = 0

    denom = arr.sum(2)
    denom[denom==0] = 1
    out[:,:,0] = red / denom
    out[:,:,1] = green / denom
    
    return out

Example 32

Project: pyDive
Source File: interengine.py
View license
def gatherArraysMPI_async(out_array, commData, target2rank):
    recv_bufs = []
    tasks = []
    for (src_target, window, tag) in commData:
        recv_bufs.append(np.empty_like(out_array[window]))
        tasks.append(MPI.COMM_WORLD.Irecv(recv_bufs[-1], source=target2rank[src_target], tag=tag))

    return tasks, recv_bufs

Example 33

Project: george
Source File: utils.py
View license
def numerical_gradient(f, x, dx=1.234e-6):
    g = np.empty_like(x, dtype=float)
    for i in range(len(g)):
        x[i] += dx
        fp = f(x)
        x[i] -= 2*dx
        fm = f(x)
        x[i] += dx
        g[i] = 0.5 * (fp - fm) / dx
    return g

Example 34

Project: distarray
Source File: localarray.py
View license
def redistribute(comm, plan, la_from, la_to):
    myrank = comm.Get_rank()
    for dta in plan:
        if dta['source_rank'] == dta['dest_rank'] == myrank:
            # simple local copy from `la_from` to `la_to`
            slices_from = make_local_slices(la_from, dta['indices'])
            slices_to = make_local_slices(la_to, dta['indices'])
            la_to.ndarray[slices_to] = la_from.ndarray[slices_from]
        elif dta['source_rank'] == myrank:
            source_slices = make_local_slices(la_from, dta['indices'])
            sliced_ndarr = la_from.ndarray[source_slices]
            sliced_buffer = sliced_ndarr.ravel()
            comm.Send(sliced_buffer, dest=dta['dest_rank'])
        elif dta['dest_rank'] == myrank:
            dest_slices = make_local_slices(la_to, dta['indices'])
            sliced_ndarr = la_to.ndarray[dest_slices]
            recv_buffer = np.empty_like(sliced_ndarr)
            comm.Recv(recv_buffer, source=dta['source_rank'])
            sliced_ndarr[...] = recv_buffer

Example 35

Project: distarray
Source File: load_volume.py
View license
def filter_avg3(a):
    ''' Filter a numpy array via 3-point average over z axis.
    A 2-point average is used at the ends. '''
    from numpy import empty_like
    b = empty_like(a)
    b[:, :, 0] = (a[:, :, 0] + a[:, :, 1]) / 2.0
    b[:, :, 1:-1] = (a[:, :, :-2] + a[:, :, 1:-1] + a[:, :, 2:]) / 3.0
    b[:, :, -1] = (a[:, :, -2] + a[:, :, -1]) / 2.0
    return b

Example 36

Project: distarray
Source File: load_volume.py
View license
def local_filter_avg3(la):
    ''' Filter a local array via 3-point average over z axis. '''

    def filter_avg3(a):
        ''' Filter a local array via 3-point average over z axis.
        A 2-point average is used at the ends. '''
        from numpy import empty_like
        b = empty_like(a)
        b[:, :, 0] = (a[:, :, 0] + a[:, :, 1]) / 2.0
        b[:, :, 1:-1] = (a[:, :, :-2] + a[:, :, 1:-1] + a[:, :, 2:]) / 3.0
        b[:, :, -1] = (a[:, :, -2] + a[:, :, -1]) / 2.0
        return b

    from distarray.localapi import LocalArray
    a = la.ndarray
    b = filter_avg3(a)
    res = LocalArray(la.distribution, buf=b)
    rtn = proxyize(res)
    return rtn

Example 37

Project: distarray
Source File: load_volume.py
View license
def filter_max3(a):
    ''' Filter a numpy array via a 3-element window maximum. '''
    from numpy import empty_like
    b = empty_like(a)
    shape = a.shape
    for k in xrange(shape[2]):
        k0 = max(k - 1, 0)
        k1 = min(k + 1, shape[2] - 1)
        b[:, :, k] = a[:, :, k0:k1 + 1].max(axis=2)
    return b

Example 38

Project: flypy
Source File: vectorize.py
View license
@jit('NDArray[dtype1, dims1] -> NDArray[dtype2, dims2] -> r')
def add(a, b):
    arrays = broadcast(a, b)
    a = head(arrays)
    b = head(tail(arrays))
    out = np.empty_like(a, unify(a.dtype, b.dtype))
    _add(a, b, out)
    return out

Example 39

Project: flypy
Source File: test_nplib.py
View license
    def test_np_empty_like(self):
        @jit
        def empty_like(a, dtype):
            return np.empty_like(a, dtype)

        a = np.empty((10, 12), dtype=np.int64)

        self.assertEqual(empty_like(a, int64).shape, a.shape)
        self.assertEqual(empty_like(a, int64).strides, a.strides)
        self.assertEqual(empty_like(a, float32).shape, a.shape)

Example 40

Project: flypy
Source File: test_nplib.py
View license
    def test_np_empty_like_no_dtype(self):
        @jit
        def empty_like(a):
            return np.empty_like(a)

        a = np.empty((10, 12), dtype=np.int64)

        # Test without dtype
        self.assertEqual(empty_like(a).shape, a.shape)
        self.assertEqual(empty_like(a).dtype, a.dtype)

Example 41

Project: robothon
Source File: extras.py
View license
def masked_all_like(arr):
    """Return an empty masked array of the same shape and dtype as
    the array `a`, where all the data are masked.

    """
    a = masked_array(np.empty_like(arr),
                     mask=np.ones(arr.shape, bool))
    return a

Example 42

Project: robothon
Source File: arrayfns.py
View license
def reverse(x, n):
    x = asarray(x,dtype='d')
    if x.ndim != 2:
        raise ValueError, "input must be 2-d"
    y = nx.empty_like(x)
    if n == 0:
        y[...] = x[::-1,:]
    elif n == 1:
        y[...] = x[:,::-1]
    return y

Example 43

Project: vsm
Source File: spatial.py
View license
def naive_cconv(v, w):
    """
    """
    out = np.empty_like(v)
    for i in xrange(v.shape[0]):
        out[i] = np.dot(v, np.roll(w[::-1], i + 1))

    return out

Example 44

Project: parakeet
Source File: rosenbrock.py
View license
def rosen_der_np(x):
  der = np.empty_like(x)
  der[1:-1] = (+ 200 * (x[1:-1] - x[:-2] ** 2)
               - 400 * (x[2:] - x[1:-1] ** 2) * x[1:-1]
               - 2 * (1 - x[1:-1]))
  der[0] = -400 * x[0] * (x[1] - x[0] ** 2) - 2 * (1 - x[0])
  der[-1] = 200 * (x[-1] - x[-2] ** 2)
  return der

Example 45

Project: parakeet
Source File: rosenbrock.py
View license
def rosen_der_loops(x):
  n = x.shape[0]
  der = np.empty_like(x)

  for i in range(1, n - 1):
    der[i] = (+ 200 * (x[i] - x[i - 1] ** 2)
              - 400 * (x[i + 1]
              - x[i] ** 2) * x[i]
              - 2 * (1 - x[i]))
  der[0] = -400 * x[0] * (x[1] - x[0] ** 2) - 2 * (1 - x[0])
  der[-1] = 200 * (x[-1] - x[-2] ** 2)
  return der

Example 46

Project: parakeet
Source File: rosenbrock.py
View license
@jit 
def rosenbrock_derivative(x):
  der = np.empty_like(x)
  der[1:-1] = (+ 200 * (x[1:-1] - x[:-2] ** 2)
               - 400 * (x[2:] - x[1:-1] ** 2) * x[1:-1]
               - 2 * (1 - x[1:-1]))
  der[0] = -400 * x[0] * (x[1] - x[0] ** 2) - 2 * (1 - x[0])
  der[-1] = 200 * (x[-1] - x[-2] ** 2)
  return der

Example 47

Project: parakeet
Source File: test_tanh_rescale.py
View license
@jit 
def loopy(x, alpha = 0.5, beta = 0.3):
  y = np.empty_like(x, dtype=float)
  for i in xrange(len(x)):
    y[i] = np.tanh(x[i]) * alpha + beta
  return y

Example 48

Project: parakeet
Source File: test_morphology.py
View license
@jit 
def dilate_decompose(x, window_size): 
  m,n = x.shape
  k,l = window_size
  y = np.empty_like(x)
  z = np.empty_like(x)
  for row_idx in xrange(m):
    dilate_1d_naive(x[row_idx,:], y[row_idx,:], k)
  for col_idx in xrange(n):
    dilate_1d_naive(y[:, col_idx], z[:, col_idx], l)
  return z

Example 49

Project: pyParticleEst
Source File: basic_model_sir.py
View license
    def qsample(self, particles, u, y, t):
        pnext = numpy.empty_like(particles)
        err = y - particles
        C = numpy.eye(1)
        P = self.Q
        S = C.dot(P).dot(C.T) + self.R
        Pn = P - P.dot(C.T).dot(scipy.linalg.solve(S, C.dot(P)))
        for i in xrange(len(pnext)):
            m = particles[i] + P.dot(C.T).dot(scipy.linalg.solve(S, err[i].reshape((-1, 1)))).ravel()
            pnext[i] = numpy.random.multivariate_normal(m, Pn).ravel()

        return pnext

Example 50

Project: pyParticleEst
Source File: basic_model_sir.py
View license
    def qsample(self, particles, u, y, t):
        pnext = numpy.empty_like(particles)
        err = y - particles
        C = numpy.eye(1)
        P = self.Q
        S = C.dot(P).dot(C.T) + self.R
        Pn = P - P.dot(C.T).dot(scipy.linalg.solve(S, C.dot(P)))
        for i in xrange(len(pnext)):
            m = particles[i] + P.dot(C.T).dot(scipy.linalg.solve(S, err[i].reshape((-1, 1)))).ravel()
            pnext[i] = numpy.random.multivariate_normal(m, Pn).ravel()

        return pnext