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

Python numpy.bitwise_xor函数代码示例

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

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



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

示例1: test_getTraining

 def test_getTraining(self):
     test = np.array(Image.open(self.filename), 'uint8')
     train = np.array(Image.open(self.filename), 'uint8')
     np.bitwise_xor(test,train,test)
     image = np.ones(test.shape,test.dtype)
     le.getTraining(image,self.filename, self.filename)
     assert((test == image).all(), True)
开发者ID:ryanbanderson,项目名称:Automated-Terrain-Mapping-of-Mars,代码行数:7,代码来源:test_load_extension.py


示例2: count_sensitive_neighborhood_hash

def count_sensitive_neighborhood_hash(g):
    """ Compute the count sensitive neighborhood hashed 
        version of a graph.
    """

    gnh = g.copy()
    g = array_labels_to_str(g)

    #iterate over every node in the graph
    for node in iter(g.nodes()):
        neighbors_labels = [g.node[n]["label"] for n in g.neighbors_iter(node)]

        #if node has no neighboors, nh is its own label
        if len(neighbors_labels) > 0:

            #count number of unique labels
            c = Counter(neighbors_labels)
            count_weighted_neighbors_labels = []
            for label, c in c.iteritems():
                label = str_to_array(label)
                c_bin = np.array( list(np.binary_repr( c, len(label) ) ), dtype=np.int64 )
                label = np.bitwise_xor( label, c_bin)
                label = np.roll( label, c )
                count_weighted_neighbors_labels.append( label )
            x = count_weighted_neighbors_labels[0]
            for l in count_weighted_neighbors_labels[1:]:
                x = np.bitwise_xor( x, l)
            node_label = str_to_array(g.node[node]["label"])
            csnh = np.bitwise_xor( np.roll( node_label, 1 ), x )
        else:
            csnh = str_to_array(g.node[node]["label"])

        gnh.node[node]["label"] = csnh

    return gnh   
开发者ID:Bludge0n,项目名称:adagio,代码行数:35,代码来源:ml.py


示例3: unmask

    def unmask(buf, f):
        s2a = lambda s: [ord(c) for c in s]
        s2b = lambda s: s

        pstart = f['hlen'] + 4
        pend = pstart + f['length']

        if numpy:
            b = c = s2b('')
            if f['length'] >= 4:
                mask = numpy.frombuffer(buf, dtype=numpy.dtype('<u4'),
                        offset=f['hlen'], count=1)
                data = numpy.frombuffer(buf, dtype=numpy.dtype('<u4'),
                        offset=pstart, count=int(f['length'] / 4))
                b = numpy.bitwise_xor(data, mask).tostring()

            if f['length'] % 4:
                mask = numpy.frombuffer(buf, dtype=numpy.dtype('B'),
                        offset=f['hlen'], count=(f['length'] % 4))
                data = numpy.frombuffer(buf, dtype=numpy.dtype('B'),
                        offset=pend - (f['length'] % 4),
                        count=(f['length'] % 4))
                c = numpy.bitwise_xor(data, mask).tostring()
            return b + c
        else:
            data = array.array('B')
            mask = s2a(f['mask'])

            data.fromstring(buf[pstart:pend])
            for i in range(len(data)):
                data[i] ^= mask[i % 4]
            return data.tostring()
开发者ID:puffin,项目名称:djangosocket,代码行数:32,代码来源:hybi.py


示例4: iota

def iota(ain, rnd):
    # Initialize empty arrays
    aout = np.zeros((5,5,64), dtype = int)
    bit = np.zeros(dtype = int, shape = (5,5,64))
    rc = np.zeros(dtype = int, shape = 168)

    # Linear Feedback Shift Register
    w = np.array([1,0,0,0,0,0,0,0], dtype = int)
    rc[0] = w[0]
    for i in range(1, 7*24):
        a = np.bitwise_xor(w[0], w[4])
        b = np.bitwise_xor(w[5], w[6])
        tail = np.bitwise_xor(a, b)
        w = [w[1],w[2],w[3],w[4],w[5],w[6],w[7], tail]
        rc[i] = w[0]
    # Calculate bits
    for l in range(7):
        q = pow(2, l) - 1
        t = l + 7*rnd
        bit[0][0][q] = rc[l + 7*rnd]
    # Calculate aout
    for i in range(5):
        for j in range(5):
            for k in range(64):
                aout[i][j][k] = np.bitwise_xor(ain[i][j][k], bit[i][j][k])
    return aout
开发者ID:evanpaul22,项目名称:pySHA-3,代码行数:26,代码来源:SHA3.py


示例5: reconciliate

def reconciliate(matlabEng, arrDelta, arrData_bin_2, n, k, m, strCoder):
    """
        Given the delta, try to deduce data1 via reconciliation
    """
    arrMsg_bin_2 = None
    arrCodeword_bin_2 = None    
    
    if (strCoder == CODER_GOLAY):
        n = 23
        k = 12
        arrMsg_bin_2 = golay.decode(matlabEng, 
                                    np.bitwise_xor(arrData_bin_2, arrDelta),
                                    n)
        arrCodeword_bin_2 = golay.encode(matlabEng, arrMsg_bin_2, k)
        
    elif (strCoder == CODER_RS):
        arrMsg_bin_2 = rs.decode(matlabEng,
                                 np.bitwise_xor(arrData_bin_2, arrDelta),
                                 n, k, m)
        arrCodeword_bin_2 = rs.encode(matlabEng, arrMsg_bin_2, n, k, m)
        
    elif (strCoder == CODER_HAMMING):
        arrMsg_bin_2 = fec.decode(matlabEng,
                                  np.bitwise_xor(arrData_bin_2, arrDelta),
                                  n, k, strCoder)
        arrCodeword_bin_2 = fec.encode(matlabEng, arrMsg_bin_2, n, k)
    else:
        raise ValueError("Unkown coder")
        
    # deduce data 1 from data 2 + delta
    arrDeducedData_bin_1 = np.bitwise_xor(arrCodeword_bin_2, arrDelta)
    
    return arrDeducedData_bin_1
开发者ID:hankes-garden,项目名称:emg_key,代码行数:33,代码来源:error_correction_coder.py


示例6: spa_model

def spa_model(plaintext, key):
    hd_arr = np.zeros(16)
    hw_arr = np.zeros(16)
    zo_arr = np.zeros(16)
    byte_list = [0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 15, 11, 7]
    for byte in byte_list:
        print 'byte: ' + str(byte)
        plaintext_nth_byte = plaintext[byte]             
        # XOR the plaintext byte with key byte and put the result through the S-BOX
        xored_plaintxt_key_bytes = np.bitwise_xor(plaintext_nth_byte, key[byte]) 
        
        # Use the Hamming Weight model to calculate the hypothetical power consumption of
        #	the SBOX operation. 
        hw_arr[byte] = num_ones(sbox_hex[xored_plaintxt_key_bytes])
        
        # Use the Hamming Distance model
        hd_arr[byte] = num_ones(np.bitwise_xor(xored_plaintxt_key_bytes, sbox_hex[xored_plaintxt_key_bytes]))

        # Other power model! 0 -> 1 transition
        zo_arr[byte] = num_ones(~xored_plaintxt_key_bytes & sbox_hex[xored_plaintxt_key_bytes])


        print '%x, %x, %d, %d, %d' %(xored_plaintxt_key_bytes, sbox_hex[xored_plaintxt_key_bytes], hw_arr[byte], hd_arr[byte], zo_arr[byte])

    plt.plot(hd_arr, 'r')
    plt.plot(hw_arr, 'b')
    plt.plot(zo_arr, 'g')
    plt.show()
开发者ID:chubbymaggie,项目名称:aes-sidechannel,代码行数:28,代码来源:sbox_sim.py


示例7: _unmask

    def _unmask(self, buf, mask):
        # Unmask a frame
        if numpy:
            plen = len(buf)
            pstart = 0
            pend = plen
            b = c = ''.encode('ascii')
            if plen >= 4:
                dtype=numpy.dtype('<u4')
                if sys.byteorder == 'big':
                    dtype = dtype.newbyteorder('>')
                mask = numpy.frombuffer(mask, dtype, count=1)
                data = numpy.frombuffer(buf, dtype, count=int(plen / 4))
                #b = numpy.bitwise_xor(data, mask).data
                b = numpy.bitwise_xor(data, mask).tostring()

            if plen % 4:
                dtype=numpy.dtype('B')
                if sys.byteorder == 'big':
                    dtype = dtype.newbyteorder('>')
                mask = numpy.frombuffer(mask, dtype, count=(plen % 4))
                data = numpy.frombuffer(buf, dtype,
                        offset=plen - (plen % 4), count=(plen % 4))
                c = numpy.bitwise_xor(data, mask).tostring()
            return b + c
        else:
            # Slower fallback
            if sys.hexversion < 0x3000000:
                mask = [ ord(c) for c in mask ]
            data = array.array('B')
            data.fromstring(buf)
            for i in range(len(data)):
                data[i] ^= mask[i % 4]
            return data.tostring()
开发者ID:PKRoma,项目名称:websockify,代码行数:34,代码来源:websocket.py


示例8: main

def main():
    
    mp.figure(1)
    mp.clf()
    ax = mp.subplot(211)
    #ax = mp.subplot(211)
    #x, y = testData()
    x, y, flag = jupiter1()
    cin = np.arange(len(x))
        
    #import pdb; pdb.set_trace()
    idx = noise.singlePointDifferenceSigmaClip(y, 4, initialClip=flag)
    mp.plot(cin[~flag],y[~flag], 'k.')
    mp.plot(cin[idx], y[idx], 'ro', ms=10)
    mp.plot(cin[flag], y[flag], 'gs')
    mp.axvline(499, color='b')
    
    mp.subplot(212, sharex=ax)
    mp.plot(cin, y - np.roll(y, -1), 'ko-')
    mp.axvline(499, color='b')
    
    outliers = np.where(np.bitwise_xor(idx, flag))[0]
    outliers = np.bitwise_xor(idx, flag).astype(int)
    
    mp.figure(2)
    mp.clf()
    mp.plot(np.convolve(outliers, outliers, mode='same'))
开发者ID:barentsen,项目名称:dave,代码行数:27,代码来源:test_singlePointDiffSigmaClip.py


示例9: sign_change

def sign_change(img):
    img = img.reshape(28, 28)
    top = numpy.bitwise_xor(img, shift_up(img))
    top = [top[:, i].sum() / 255 for i in xrange(img.shape[1])]
    side = numpy.bitwise_xor(img, shift_left(img))
    side = [side[i, :].sum() / 255 for i in xrange(img.shape[1])]
    return numpy.array(top), numpy.array(side)
开发者ID:democraciaconcodigos,项目名称:recon,代码行数:7,代码来源:features.py


示例10: detect_corruption

 def detect_corruption(self, fname):
     """
     single disk corruption detection
     :param fname: data name in RAID6 system
     :return: corrupted disk index; for p, self.N-2; for q, self.N-1
     """
     # all disks, including P, Q
     byte_ndarray = self._read_n(fname, self.N)
     data_ndarray = byte_ndarray[:-2]
     self._logger.info("byte_ndarray=\n{}".format(byte_ndarray))
     P = byte_ndarray[-2:-1]
     self._logger.info("p={}".format(P))
     Q = byte_ndarray[-1]
     self._logger.info("Q={}".format(Q))
     P_prime = utils.gen_p(data_ndarray, ndim=2)
     self._logger.info("P_prime={}".format(P_prime))
     Q_prime = utils.gen_q(data_ndarray, ndim=2)
     self._logger.info("Q_prime={}".format(Q_prime))
     P_star = np.bitwise_xor(P, P_prime)
     Q_star = np.bitwise_xor(Q, Q_prime)
     P_nonzero = np.count_nonzero(P_star)
     Q_nonzero = np.count_nonzero(Q_star)
     if P_nonzero == 0 and Q_nonzero == 0:
         print("no corruption")
         return None
     elif P_nonzero == 0 and Q_nonzero != 0:
         print("Q corruption")
         return self.N - 1
     elif P_nonzero != 0 and Q_nonzero == 0:
         print("P corruption")
         return self.N - 2
     else:
         index = self._get_corrupted_data_disk(P_star, Q_star)
         print("data disk {} corruption".format(index))
         return index
开发者ID:HongxuChen,项目名称:CE7490_2,代码行数:35,代码来源:raid6.py


示例11: chi

def chi(ain):
    aout = np.zeros((5,5,64), dtype = int) # Initialize empty 5x5x64 array

    for i in range(5):
        for j in range(5):
            for k in range(64):
                xor = np.bitwise_xor(ain[(i+1)%5][j][k], 1)
                mul = xor * (ain[(i+2)%5][j][k])
                aout[i][j][k] = np.bitwise_xor(ain[i][j][k], mul)
    return aout
开发者ID:evanpaul22,项目名称:pySHA-3,代码行数:10,代码来源:SHA3.py


示例12: train_and_test

def train_and_test(X_train,Y_train,X_test,Y_test,dtype,alpha,beta_percentile,cv=True):
	k = X_train.shape[0]
	n = X_test.shape[0]

	A = np.zeros(shape=(k,k))
	lambd = 1
	part1 = np.column_stack((X_train['guarantee_type'], X_train['gender']))
	part2 = np.column_stack((X_train['age'], X_train['account_value'], X_train['withdrawal_rate'],X_train['maturity']))

	for i in range(k):
		tmp = np.array([X_train[i],]*k, dtype=dtype)	
		tmp1 = np.column_stack((tmp['guarantee_type'], tmp['gender']))	#copy this row k times
		tmp2 = np.column_stack((tmp['age'], tmp['account_value'], tmp['withdrawal_rate'],tmp['maturity']))
		result1 = lambd*np.sum(np.bitwise_xor(part1, tmp1), axis=1)
		result2 = np.sum((part2-tmp2)**2,axis=1)
		A[i] = np.sqrt(result1+result2)

	# tmp = np.triu(A)
	# tmp = tmp[tmp!=0]
	max_dist = A.max()
	B = np.zeros(shape=(k+1,k+1))
	B[k] = B[:,k] = 1
	B[k,k] = 0	

	part1 = np.column_stack((X_test['guarantee_type'], X_test['gender']))
	part2 = np.column_stack((X_test['age'], X_test['account_value'], X_test['withdrawal_rate'],X_test['maturity']))

	weight_mat = np.zeros((k+1,n))
	weight_mat[k] = 1
	beta = max_dist*beta_percentile

	for j in range(k):
		B[j][:k] = alpha+np.exp(-3*A[j]/beta)	
		tmp = np.array([X_train[j],]*n, dtype=dtype)	
		tmp1 = np.column_stack((tmp['guarantee_type'], tmp['gender']))	#copy this row k times
		tmp2 = np.column_stack((tmp['age'], tmp['account_value'], tmp['withdrawal_rate'],tmp['maturity']))
		result1 = lambd*np.sum(np.bitwise_xor(part1, tmp1), axis=1)
		result2 = np.sum((part2-tmp2)**2,axis=1)
		weight_mat[j] = alpha+np.exp(np.sqrt(result1+result2)*(-3/beta))

	Y_train = np.append(Y_train, 0)
	const = np.dot(np.linalg.inv(B),Y_train)
	Y_hat = np.dot(const, weight_mat)
	
	if cv == True:
		RMSE = np.sqrt(sum((Y_test-Y_hat)**2)/n)
		return RMSE
	else:
		RMSE = np.sqrt(sum((Y_test-Y_hat)**2)/(n+k))
		MAD = sum(abs(Y_test-Y_hat))/(n+k)
		total = sum(Y_hat)+sum(Y_train)
		benchmark = sum(Y_test)+sum(Y_train)
		APD = abs(total-benchmark)
		RPD = APD/benchmark	
		return APD,RPD,MAD,RMSE
开发者ID:chrisplyn,项目名称:cm_project,代码行数:55,代码来源:kriging.py


示例13: xor_arrays

    def xor_arrays(cls, source, target):
        """
        Moved to its own function for profiling purposes.
        May want to consider moving out to inline.
        The source array will be xored into place into
        the target array

        Arguments:
        source -- Numpy array source array
        target -- Numpy array target array
        """
        numpy.bitwise_xor(source, target, target)
开发者ID:absalon-james,项目名称:velopyraptor,代码行数:12,代码来源:raptor.py


示例14: key_expansion

    def key_expansion(self, cipher_key):
        if self.is_verbose:
            print "Computing key schedule..."

        key_schedule = np.copy(cipher_key)
        n_k = len(cipher_key)
        n_r = n_k + 6

        if self.is_verbose:
            print
            print "               After     After      Rcon      XOR"
            print " i  Previous  RotWord   SubWord    Value    w/ Rcon   w[i-Nk]    Final"
            print "=== ========  ========  ========  ========  ========  ========  ========"

        for i in range(n_k, N_B * (n_r + 1)):
            prev = key_schedule[i - 1]
            first = key_schedule[i - n_k]
            temp = prev
            after_rot_word = None
            after_sub_word = None
            rcon_val = None
            after_xor_rcon = None

            if i % n_k == 0:
                after_rot_word = rot_word(prev)
                after_sub_word = sub_word(after_rot_word)
                rcon_val = rcon(i / n_k)
                after_xor_rcon = np.bitwise_xor(after_sub_word, rcon_val)
                temp = after_xor_rcon
            elif n_k > 6 and i % n_k == 4:
                after_sub_word = sub_word(prev)
                temp = after_sub_word

            final = np.bitwise_xor(first, temp)

            key_schedule = np.append(key_schedule, final.reshape(1, 4), axis=0)

            if self.is_verbose:
                print "{:02}: {}  {}  {}  {}  {}  {}  {}".format(
                    i,
                    w2s(prev),
                    w2s(after_rot_word),
                    w2s(after_sub_word),
                    w2s(rcon_val),
                    w2s(after_xor_rcon),
                    w2s(first),
                    w2s(final),
                )

        if self.is_verbose:
            print

        return key_schedule, n_k, n_r
开发者ID:keith-mcqueen,项目名称:PyCipher,代码行数:53,代码来源:pycipher.py


示例15: expand_key

 def expand_key(self, key):
     self.round_keys = []
     self.round_keys.append(key)
     for i in range(1, NUM_ROUNDS+1):
         # Always transpose, words are columns and not rows
         previous_key = self.round_keys[i-1].transpose()
         round_key = np.zeros(key.shape, dtype=np.uint8)
         round_key[0] = np.bitwise_xor(self.g(previous_key[3], i),
                                       previous_key[0])
         round_key[1] = np.bitwise_xor(round_key[0], previous_key[1])
         round_key[2] = np.bitwise_xor(round_key[1], previous_key[2])
         round_key[3] = np.bitwise_xor(round_key[2], previous_key[3])
         self.round_keys.append(round_key.transpose())
开发者ID:gabrielssilva,项目名称:crypto-progs,代码行数:13,代码来源:aes.py


示例16: add_noise

def add_noise(y, x, noise_y_rate, noise_x_rate):
    assert(noise_y_rate >= 0 and noise_y_rate <= 1)
    assert(noise_x_rate >= 0 and noise_x_rate <= 1)

    tmp_y = (y + np.ones_like(y)) / 2
    noise_y = np.random.random(y.shape) < noise_y_rate

    new_y = np.bitwise_xor(tmp_y, noise_y)
    new_y = (2 * new_y) - np.ones_like(new_y)

    noise_x = np.random.random(x.shape) < noise_x_rate
    new_x = np.bitwise_xor(x, noise_x)

    return (new_y, new_x)
开发者ID:DarwinSenior,项目名称:CS446,代码行数:14,代码来源:add_noise.py


示例17: ErrorCorrection

  def ErrorCorrection(self,syndrome,inBits):
  # LUT based error correction
  # errVector = find( errorSyndromes == syndrome );
  # if numel(errVector)>1
  #   disp('Help!');
  # end
  # if isempty(errVector)
  #   failure = true;
  # else
  #   inBits = bitxor(inBits,errorVectors(errVector(1),:));
  #   failure = false;
  # end

    corrected = 0;
    if(syndrome):
      # Meggitt algorithm, only correct data bits (16), not the parity bits
      for ndx in range(16):
        
        # The first (most significant) bit is one
        if (np.bitwise_and(syndrome,512)):
          # If the first bit is a one and the last 5 (least significant bits)
          # are zero, this indicates an error at the current bit (ndx) position
          if (np.bitwise_and(syndrome,31) == 0):
            # The code can correct bursts up to 5 bits long.  Check to see if
            # the error is a burst or not.  If it isn't a burst, it isn't
            # correctable, return immediately with a failure.
            tmp = np.bitwise_and(syndrome,480);
            if ~(tmp == 480 | tmp == 448 | tmp == 384 | tmp == 256 | tmp == 0):
              break;
            # The error appears to be a burst error, attempt to correct
            inBits[ndx] = np.bitwise_xor(inBits(ndx),1);
            # Shift the syndrome
            syndrome = np.left_shift(syndrome,1);
          else:
            # Least significant bits do not indicate the current bit (ndx) is
            # an error in a burst.  Continue shifting the syndrome and then apply the
            # generator polynomial.
            syndrome = np.left_shift(syndrome,1);
            syndrome = np.bitwise_xor(syndrome,441);
        else:
          # Not a one at the first (most significant) syndrome bit, applying generator polynomial
          # is trivial in this case.
          syndrome = np.left_shift(syndrome,1);
      # If after this process the syndrome is not zero, there was a
      # uncorrectable error.
      if (np.bitwise_and(syndrome,1023)==0):
        corrected = 1;
    return (inBits, corrected);
开发者ID:dswiston,项目名称:pyFmRadio,代码行数:48,代码来源:rds.py


示例18: execute

 def execute(self, slot, subindex, roi, result):
     assert slot == self.Output, "Unknown output slot: {}".format( slot.name )
     if self.SelectedLabel.value == 0:
         result[:] = 0
     else:
         # Can't use writeInto() here because dtypes don't match.
         inputLabels = self.Input(roi.start, roi.stop).wait()
         
         # Use two in-place bitwise operations instead of numpy.where
         # This avoids the temporary variable created by (inputLabels == x)
         #result[:] = numpy.where( inputLabels == self.SelectedLabel.value, 1, 0 )
         numpy.bitwise_xor(inputLabels, self.SelectedLabel.value, out=inputLabels) # All 
         numpy.logical_not(inputLabels, out=inputLabels)
         result[:] = inputLabels # Copy from uint32 to uint8
         
     return result
开发者ID:christophdecker,项目名称:lazyflow,代码行数:16,代码来源:opSelectLabel.py


示例19: query_with_distances

    def query_with_distances(self, v, n):
        """Find indices of `n` most similar vectors from the index to query vector `v`."""
        if self._metric == 'hamming':
            v = numpy.packbits(v)

        if self._metric != 'jaccard':
            # use same precision for query as for index
            v = numpy.ascontiguousarray(v, dtype = self.index.dtype)

        # HACK we ignore query length as that's a constant not affecting the final ordering
        if self._metric == 'angular':
            # argmax_a cossim(a, b) = argmax_a dot(a, b) / |a||b| = argmin_a -dot(a, b)
            dists = -numpy.dot(self.index, v)
        elif self._metric == 'euclidean':
            # argmin_a (a - b)^2 = argmin_a a^2 - 2ab + b^2 = argmin_a a^2 - 2ab
            dists = self.lengths - 2 * numpy.dot(self.index, v)
        elif self._metric == 'hamming':
            diff = numpy.bitwise_xor(v, self.index)
            pc = BruteForceBLAS.popcount
            den = float(len(v) * 8)
            dists = [sum([pc[part] for part in point]) / den for point in diff]
        elif self._metric == 'jaccard':
            dists = [pd[self._metric]['distance'](v, e) for e in self.index]
        else:
            assert False, "invalid metric"  # shouldn't get past the constructor!
        nearest_indices = numpy.argpartition(dists, n)[:n]  # partition-sort by distance, get `n` closest
        indices = [idx for idx in nearest_indices if pd[self._metric]["distance_valid"](dists[idx])]
        def fix(index):
            ep = self.index[index]
            ev = v
            if self._metric == "hamming":
                ep = numpy.unpackbits(ep)
                ev = numpy.unpackbits(ev)
            return (index, pd[self._metric]['distance'](ep, ev))
        return map(fix, indices)
开发者ID:ilyaraz,项目名称:ann-benchmarks,代码行数:35,代码来源:bruteforce.py


示例20: get_synthetic_clusters_dataset

def get_synthetic_clusters_dataset(n_clusters = 4, n_dims = 20, n_training = 1000, n_test = 200,
        sparsity = 0.5, flip_noise = 0.1, seed = 3425):
    """
    A dataset consisting of clustered binary data with "bit-flip" noise, and the corresponding cluster labels.
    This should be trivially solvable by any classifier, and serves as a basic test of whether your classifier is
    completely broken or not.

    :param n_clusters:
    :param n_dims:
    :param n_samples_training:
    :param n_samples_test:
    :param sparsity:
    :param flip_noise:
    :param seed:
    :return:
    """

    rng = np.random.RandomState(seed)
    labels = rng.randint(n_clusters, size = n_training+n_test)  # (n_samples, )
    centers = rng.rand(n_clusters, n_dims) < sparsity  # (n_samples, n_dims)
    input_data = centers[labels]
    input_data = np.bitwise_xor(input_data, rng.rand(*input_data.shape) < flip_noise)

    return DataSet(
        training_set = DataCollection(input_data[:n_training], labels[:n_training]),
        test_set = DataCollection(input_data[n_training:], labels[n_training:]),
        name = 'Synthetic Clusters Dataset'
        )
开发者ID:robbertvanginkel,项目名称:plato,代码行数:28,代码来源:synthetic_clusters.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python numpy.blackman函数代码示例发布时间:2022-05-27
下一篇:
Python numpy.bitwise_or函数代码示例发布时间: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