• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python numpy.copyto函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中numpy.copyto函数的典型用法代码示例。如果您正苦于以下问题:Python copyto函数的具体用法?Python copyto怎么用?Python copyto使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了copyto函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: guess_data_type

def guess_data_type(orig_values, namask=None):
    """
    Use heuristics to guess data type.
    """
    valuemap, values = None, orig_values
    is_discrete = is_discrete_values(orig_values)
    if is_discrete:
        valuemap = sorted(is_discrete)
        coltype = DiscreteVariable
    else:
        # try to parse as float
        orig_values = np.asarray(orig_values)
        if namask is None:
            namask = isnastr(orig_values)
        values = np.empty_like(orig_values, dtype=float)
        values[namask] = np.nan
        try:
            np.copyto(values, orig_values, where=~namask, casting="unsafe")
        except ValueError:
            tvar = TimeVariable('_')
            try:
                values[~namask] = [tvar.parse(i) for i in orig_values[~namask]]
            except ValueError:
                coltype = StringVariable
                # return original_values
                values = orig_values
            else:
                coltype = TimeVariable
        else:
            coltype = ContinuousVariable
    return valuemap, values, coltype
开发者ID:lanzagar,项目名称:orange3,代码行数:31,代码来源:io.py


示例2: testTensorAccessor

 def testTensorAccessor(self):
   """Check that tensor returns a reference."""
   array_ref = self.interpreter.tensor(self.input0)
   np.copyto(array_ref(), self.initial_data)
   self.assertAllEqual(array_ref(), self.initial_data)
   self.assertAllEqual(
       self.interpreter.get_tensor(self.input0), self.initial_data)
开发者ID:Albert-Z-Guo,项目名称:tensorflow,代码行数:7,代码来源:interpreter_test.py


示例3: _copyto

def _copyto(a, val, mask):
    """
    Replace values in `a` with NaN where `mask` is True.  This differs from
    copyto in that it will deal with the case where `a` is a numpy scalar.

    Parameters
    ----------
    a : ndarray or numpy scalar
        Array or numpy scalar some of whose values are to be replaced
        by val.
    val : numpy scalar
        Value used a replacement.
    mask : ndarray, scalar
        Boolean array. Where True the corresponding element of `a` is
        replaced by `val`. Broadcasts.

    Returns
    -------
    res : ndarray, scalar
        Array with elements replaced or scalar `val`.

    """
    if isinstance(a, np.ndarray):
        np.copyto(a, val, where=mask, casting='unsafe')
    else:
        a = a.dtype.type(val)
    return a
开发者ID:BranYang,项目名称:numpy,代码行数:27,代码来源:nanfunctions.py


示例4: npArrayToReadOnlySharedArray

def npArrayToReadOnlySharedArray(npArray):
    '''Returns a shared memory array for a numpy array.  Used to reduce memory footprint when passing parameters to multiprocess pools'''
    SharedBase = multiprocessing.sharedctypes.RawArray(ctypes.c_float, npArray.shape[0] * npArray.shape[1])
    SharedArray = np.ctypeslib.as_array(SharedBase)
    SharedArray = SharedArray.reshape(npArray.shape)
    np.copyto(SharedArray, npArray)
    return SharedArray
开发者ID:nornir,项目名称:nornir-imageregistration,代码行数:7,代码来源:core.py


示例5: __call__

    def __call__(self, key, value):
        key = self.path + key.lstrip('/')
        if not self.strict and key not in self.npz:
            return value

        if isinstance(self.ignore_names, (tuple, list)):
            ignore_names = self.ignore_names
        else:
            ignore_names = (self.ignore_names,)
        for ignore_name in ignore_names:
            if isinstance(ignore_name, str):
                if key == ignore_name:
                    return value
            elif callable(ignore_name):
                if ignore_name(key):
                    return value
            else:
                raise ValueError(
                    'ignore_names needs to be a callable, string or '
                    'list of them.')

        dataset = self.npz[key]
        if dataset[()] is None:
            return None

        if value is None:
            return dataset
        elif isinstance(value, numpy.ndarray):
            numpy.copyto(value, dataset)
        elif isinstance(value, cuda.ndarray):
            value.set(numpy.asarray(dataset))
        else:
            value = type(value)(numpy.asarray(dataset))
        return value
开发者ID:unnonouno,项目名称:chainer,代码行数:34,代码来源:npz.py


示例6: learn_parameters

def learn_parameters(adj_list, q, c_max, nb_iterations, crit_infer = 0.2, crit_learn = 0.2, tmax_infer = 12, tmax_learn = 8):
	"""
	Learns the true group parameters of a given graph, and returns the optimal group assignment given by the belief
	propagation algorithm
	"""
	# Number of nodes on the graph
	N = len(adj_list)

	# Optimal values given by the algorithm
	f_min = 0
	groups_opt = np.zeros(N, dtype = np.int8)
	for _ in range(nb_iterations):
		# Random initialization of each group's size
		n = np.random.rand(q)
		n /= np.sum(n)
		
		# Random initialization of the edge matrix
		c = np.random.rand(q, q)
		for i in range(q - 1):
			for j in range(i + 1, q):
				c[j, i] = c[i, j]
		c *= c_max

		# Application of the BP_learning algorithm for these initialized values
		groups, f_BP = BP_learning(q, n, c, adj_list, crit_infer, crit_learn, tmax_infer, tmax_learn)

		# Updates the optimal values found
		if f_BP < f_min:
			f_min = f_BP
			np.copyto(groups_opt, groups)

	# Returns the optimal group assignment found
	return groups_opt
开发者ID:davisilva15,项目名称:Community-Detection,代码行数:33,代码来源:belief_propagation.py


示例7: binary_to_net

def binary_to_net(weights, spm_stream, ind_stream, codebook, num_nz):
    bits = np.log2(codebook.size)
    if bits == 4:
        slots = 2
    elif bits == 8:
        slots = 1
    else:
        print "Not impemented,", bits
        sys.exit()
    code = np.zeros(weights.size, np.uint8) 

    # Recover from binary stream
    spm = np.zeros(num_nz, np.uint8)
    ind = np.zeros(num_nz, np.uint8)
    if slots == 2:
        spm[np.arange(0, num_nz, 2)] = spm_stream % (2**4)
        spm[np.arange(1, num_nz, 2)] = spm_stream / (2**4)
    else:
        spm = spm_stream
    ind[np.arange(0, num_nz, 2)] = ind_stream% (2**4)
    ind[np.arange(1, num_nz, 2)] = ind_stream/ (2**4)


    # Recover the matrix
    ind = np.cumsum(ind+1)-1
    code[ind] = spm
    data = np.reshape(codebook[code], weights.shape)
    np.copyto(weights, data)
开发者ID:lvchigo,项目名称:demo_nn_compress,代码行数:28,代码来源:decode.py


示例8: apply_qt_elements_filtering

 def apply_qt_elements_filtering(image):
     #
     # apply bilateral filter on IMAGE to smooth colors while keeping edges
     cv2.bilateralFilter(UtilityOperations.crop_to_720p(image), 3, 255, 50,
                         dst=MultiprocessOperations.shared_memory_image)
     #
     # crop elements from IMAGE
     MultiprocessOperations.wait_for_element_cropping()
     #
     # upload RED channels to GPU
     TheanoOperations.__shared_red.set_value(
         MultiprocessOperations.shared_memory_red_channel, borrow=True)
     #
     # upload GREEN channels to GPU
     TheanoOperations.__shared_green.set_value(
         MultiprocessOperations.shared_memory_green_channel, borrow=True)
     #
     # upload BLUE channels to GPU
     TheanoOperations.__shared_blue.set_value(
         MultiprocessOperations.shared_memory_blue_channel, borrow=True)
     #
     # download FILTERING result from GPU
     np.copyto(MultiprocessOperations.shared_memory_qt_filtered_elements,
               TheanoOperations.__apply_binary_filtering)
     #
     # apply IMAGE threshold CLASSIFICATION
     MultiprocessOperations.wait_for_qt_image_classification()
     return MultiprocessOperations.shared_memory_qt_filtered_elements
开发者ID:clubcapra,项目名称:ngv_dev,代码行数:28,代码来源:ngv_filter.py


示例9: set_rho

    def set_rho(self, rho):
        """
        Set the initial density matrix
        :param rho: 2D numpy array or sting containing the density matrix
        :return: self
        """
        if isinstance(rho, str):
            # density matrix is supplied as a string
            ne.evaluate("%s + 0j" % rho, local_dict=vars(self), out=self.rho)

        elif isinstance(rho, np.ndarray):
            # density matrix is supplied as an array

            # perform the consistency checks
            assert rho.shape == self.rho.shape,\
                "The grid size does not match with the density matrix"

            # make sure the density matrix is stored as a complex array
            np.copyto(self.rho, rho.astype(np.complex))

        else:
            raise ValueError("density matrix must be either string or numpy.array")

        # normalize
        self.rho /= self.rho.trace() * self.dX

        return self
开发者ID:dibondar,项目名称:QuantumClassicalDynamics,代码行数:27,代码来源:split_op_denisty_matrix.py


示例10: _load_flat_grad

 def _load_flat_grad(self, flat_grad):
   start = 0
   for g in self._grad_buffers:
     size = g.size
     np.copyto(g, np.reshape(flat_grad[start:start + size], g.shape))
     start += size
   return
开发者ID:bulletphysics,项目名称:bullet3,代码行数:7,代码来源:mpi_solver.py


示例11: serialize

    def serialize(self, serializer):
        """Serializes the link object.

        Args:
            serializer (~chainer.AbstractSerializer): Serializer object.

        """
        d = self.__dict__
        for name in self._params:
            serializer(name, d[name].data)
        for name in self._persistent:
            d[name] = serializer(name, d[name])
        if (self.has_uninitialized_params and
                isinstance(serializer, chainer.serializer.Serializer)):
            raise ValueError("uninitialized parameters cannot be serialized")
        for name in self._uninitialized_params.copy():
            # Note: There should only be uninitialized parameters
            # during deserialization.
            initialized_value = serializer(name, None)
            self.add_param(name, initialized_value.shape)
            uninitialized_value = d[name].data
            if isinstance(uninitialized_value, numpy.ndarray):
                numpy.copyto(uninitialized_value, initialized_value)
            elif isinstance(uninitialized_value, cuda.ndarray):
                uninitialized_value.set(numpy.asarray(initialized_value))
开发者ID:KotaroSetoyama,项目名称:chainer,代码行数:25,代码来源:link.py


示例12: use

    def use(self, dataset):
        """
        Computes and returns the outputs of the Learner for
        ``dataset``:
        - the outputs should be a Numpy 2D array of size
          len(dataset) by (nb of classes + 1)
        - the ith row of the array contains the outputs for the ith example
        - the outputs for each example should contain
          the predicted class (first element) and the
          output probabilities for each class (following elements)
        Argument ``dataset`` is an MLProblem object.
        """

        outputs = np.zeros((len(dataset), self.n_classes + 1))
        errors = np.zeros((len(dataset), 2))

        ## PUT CODE HERE ##
        # row[0] is input.csv image (array), row[1] actual target class for that image
        for ind, row in enumerate(dataset):
            # fill 2nd element with loss
            errors[ind, 1] = self.fprop(row[0], row[1])
            # predicted class
            outputs[ind, 0] = np.argmax(self.hs[-1])
            # 0/1 classification error
            errors[ind, 0] = (outputs[ind, 0] != row[1])
            #             print "errors: ", errors[ind, ]
            # add output probs
            np.copyto(outputs[ind, 1:], self.hs[-1])
        #             print "outputs: ", outputs[ind,]
        #             time.sleep(5)

        return outputs, errors
开发者ID:JonnyTran,项目名称:ML-algorithms,代码行数:32,代码来源:nnet.py


示例13: lieberfit

def lieberfit(Data,Order=5):


	import numpy as np


	NewCurve = np.zeros(shape=(Data.shape[0]))
	OldCurve = np.array(Data)
	Diff = NewCurve-OldCurve
	Convergence = np.dot(Diff,Diff)


	m = 0
	while Convergence > 1: # Suggest setting convergence criteria == pixel resolution
		P = np.polyfit(range(len(Data)),OldCurve,Order)
		NewCurve = np.polyval(P,range(len(Data)))
		np.copyto(OldCurve, NewCurve, where = NewCurve < OldCurve)
		m+=1
		Diff = NewCurve - OldCurve
		Convergence = np.dot(Diff,Diff)
	#print('Iterations needed for convergence: ',m,sep='')


	CurveFit=np.copy(NewCurve)


	return (CurveFit)
开发者ID:dbricare,项目名称:spectra,代码行数:27,代码来源:ModPolyFit.py


示例14: revert_all

    def revert_all(self, clear=False):
        '''return the image to it's original state'''
        np.copyto(self.image, self.ref_image)

        if clear:
            self.clear_history()
            self.drawing.reset()
开发者ID:zshipko,项目名称:imagepy,代码行数:7,代码来源:alias.py


示例15: draw_bounding_box_on_image_array

def draw_bounding_box_on_image_array(image,
                                     ymin,
                                     xmin,
                                     ymax,
                                     xmax,
                                     color='red',
                                     thickness=4,
                                     display_str_list=(),
                                     use_normalized_coordinates=True):
  """Adds a bounding box to an image (numpy array).

  Bounding box coordinates can be specified in either absolute (pixel) or
  normalized coordinates by setting the use_normalized_coordinates argument.

  Args:
    image: a numpy array with shape [height, width, 3].
    ymin: ymin of bounding box.
    xmin: xmin of bounding box.
    ymax: ymax of bounding box.
    xmax: xmax of bounding box.
    color: color to draw bounding box. Default is red.
    thickness: line thickness. Default value is 4.
    display_str_list: list of strings to display in box
                      (each to be shown on its own line).
    use_normalized_coordinates: If True (default), treat coordinates
      ymin, xmin, ymax, xmax as relative to the image.  Otherwise treat
      coordinates as absolute.
  """
  image_pil = Image.fromarray(np.uint8(image)).convert('RGB')
  draw_bounding_box_on_image(image_pil, ymin, xmin, ymax, xmax, color,
                             thickness, display_str_list,
                             use_normalized_coordinates)
  np.copyto(image, np.array(image_pil))
开发者ID:zhangjiulong,项目名称:models,代码行数:33,代码来源:visualization_utils.py


示例16: test_array_maskna_to_nomask

def test_array_maskna_to_nomask():
    # Assignment from an array with NAs to a non-masked array,
    # excluding the NAs with a mask
    a = np.array([[2,np.NA,5],[1,6,np.NA]], maskna=True)
    mask = np.array([[1,0,0],[1,1,0]], dtype='?')
    badmask = np.array([[1,0,0],[0,1,1]], dtype='?')
    expected = np.array([[2,1,2],[1,6,5]])

    # With masked indexing
    b = np.arange(6).reshape(2,3)
    b[mask] = a[mask]
    assert_array_equal(b, expected)

    # With copyto
    b = np.arange(6).reshape(2,3)
    np.copyto(b, a, where=mask)
    assert_array_equal(b, expected)

    # With masked indexing
    b = np.arange(6).reshape(2,3)
    def asn():
        b[badmask] = a[badmask]
    assert_raises(ValueError, asn)

    # With copyto
    b = np.arange(6).reshape(2,3)
    assert_raises(ValueError, np.copyto, b, a, where=badmask)
开发者ID:beniamino38,项目名称:numpy,代码行数:27,代码来源:test_maskna.py


示例17: laplacian

def laplacian(grid, out):
    copyto(out, grid)
    multiply(out, -4.0, out)
    roll_add(grid, +1, 0, out)
    roll_add(grid, -1, 0, out)
    roll_add(grid, +1, 1, out)
    roll_add(grid, -1, 1, out)
开发者ID:ChinaQuants,项目名称:high_performance_python,代码行数:7,代码来源:diffusion_numpy_memory2_numexpr.py


示例18: __init__

 def __init__(self, W = 20, H = 20):
     """ Inicializa Variables """
     self.WIDTH = W
     self.HEIGHT = H
     self.prevState = numpy.zeros((self.HEIGHT,self.WIDTH))
     self.nextState = numpy.zeros((self.HEIGHT,self.WIDTH))
     numpy.copyto(self.prevState,self.nextState)
开发者ID:wibowo87,项目名称:conway,代码行数:7,代码来源:conway.py


示例19: embed

def embed(cover,secret,pos,skip):
    file=open("in.txt","w")
    multiple=False
    coverMatrix=pgm_to_mat(cover)
    secretMatrix=pgm_to_mat(secret)
    stegoMatrix=np.zeros(np.shape(coverMatrix), dtype=np.complex_)
    np.copyto(stegoMatrix,coverMatrix)
    dummy=""
    if(skip<1):
        skip=1
        multiple=True
    for a in range(0,len(secretMatrix)):
        for b in range(0,len(secretMatrix)):
            dummy+=np.binary_repr(secretMatrix[a][b],width=8)
            #file.write(np.binary_repr(secretMatrix[a][b],width=8)+"\n")
    index=0
    for a in range(0,len(stegoMatrix)*len(stegoMatrix),skip):
        rown=int(a % len(stegoMatrix))
        coln=int(a / len(stegoMatrix))
        if(index>=len(dummy)):
            break
        stegoMatrix[coln][rown] = ( int(coverMatrix[coln][rown]) & ~(1 << hash(coln,rown,pos) )) | (int(dummy[index],2) << hash(coln,rown,pos))
        index += 1
        if(multiple):
            stegoMatrix[coln][rown] = (int(stegoMatrix[coln][rown]) & ~(1 << (3-hash(coln, rown, pos)))) | ( int(dummy[index], 2) << (3-hash(coln, rown, pos)))
            index += 1
        file.write(np.binary_repr(int(stegoMatrix[coln][rown]), 8) + "\n")
    return stegoMatrix
开发者ID:HeLLLBoY626,项目名称:ImageProcessing,代码行数:28,代码来源:stego.py


示例20: conditional_logsumexp

 def conditional_logsumexp(where, axis):
     masked = -np.ones(a.shape) * np.inf
     np.copyto(masked, a, where = where)
     masked_sum = logsumexp(masked, axis = axis)
     #np.copyto(masked_sum,  -np.ones(masked_sum.shape) * np.inf, where = np.isnan(masked_sum)) 
     np.place(masked_sum, np.isnan(masked_sum), -np.inf)
     return masked_sum
开发者ID:ingmarschuster,项目名称:ModelSelection,代码行数:7,代码来源:estimator_statistics.py



注:本文中的numpy.copyto函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python numpy.corrcoef函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.copysign函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap