python类invert()的实例源码

copula.py 文件源码 项目:mixedvines 作者: asnelt 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def logpdf(self, samples):
        '''
        Calculates the log of the probability density function.

        Parameters
        ----------
        samples : array_like
            n-by-2 matrix of samples where n is the number of samples.

        Returns
        -------
        vals : ndarray
            Log of the probability density function evaluated at `samples`.
        '''
        samples = np.copy(np.asarray(samples))
        samples = self.__rotate_input(samples)
        inner = np.all(np.bitwise_and(samples > 0.0, samples < 1.0), axis=1)
        outer = np.invert(inner)
        vals = np.zeros(samples.shape[0])
        vals[inner] = self._logpdf(samples[inner, :])
        # Assign zero mass to border
        vals[outer] = -np.inf
        return vals
restart_test.py 文件源码 项目:veros 作者: dionhaefner 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def set_initial_conditions(self):
        # initial conditions
        self.temp[:, :, :, 0:2] = ((1 - self.zt[None, None, :] / self.zw[0]) * 15 * self.maskT)[..., None]
        self.salt[:, :, :, 0:2] = 35.0 * self.maskT[..., None]

        # wind stress forcing
        taux = np.zeros(self.ny + 1, dtype=self.default_float_type)
        yt = self.yt[2:self.ny + 3]
        taux = (.1e-3 * np.sin(np.pi * (self.yu[2:self.ny + 3] - yu_start) / (-20.0 - yt_start))) * (yt < -20) \
             + (.1e-3 * (1 - np.cos(2 * np.pi * (self.yu[2:self.ny + 3] - 10.0) / (yu_end - 10.0)))) * (yt > 10)
        self.surface_taux[:, 2:self.ny + 3] = taux * self.maskU[:, 2:self.ny + 3, -1]

        # surface heatflux forcing
        self.t_star = 15 * np.invert((self.yt < -20) | (self.yt > 20)) \
            + 15 * (self.yt - yt_start) / (-20 - yt_start) * (self.yt < -20) \
            + 15 * (1 - (self.yt - 20) / (yt_end - 20)) * (self.yt > 20.)
        self.t_rest = self.dzt[np.newaxis, -1] / (30. * 86400.) * self.maskT[:, :, -1]

        if self.enable_tke:
            self.forc_tke_surface[2:-2, 2:-2] = np.sqrt((0.5 * (self.surface_taux[2:-2, 2:-2] + self.surface_taux[1:-3, 2:-2]))**2
                                                      + (0.5 * (self.surface_tauy[2:-2, 2:-2] + self.surface_tauy[2:-2, 1:-3]))**2)**(1.5)

        if self.enable_idemix:
            self.forc_iw_bottom[:] = 1.0e-6 * self.maskW[:, :, -1]
            self.forc_iw_surface[:] = 0.1e-6 * self.maskW[:, :, -1]
download_data.py 文件源码 项目:arc-pytorch 作者: sanyam5 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def omniglot_folder_to_NDarray(path_im):
    alphbts = os.listdir(path_im)
    ALL_IMGS = []

    for alphbt in alphbts:
        chars = os.listdir(os.path.join(path_im, alphbt))
        for char in chars:
            img_filenames = os.listdir(os.path.join(path_im, alphbt, char))
            char_imgs = []
            for img_fn in img_filenames:
                fn = os.path.join(path_im, alphbt, char, img_fn)
                I = imread(fn)
                I = np.invert(I)
                char_imgs.append(I)
            ALL_IMGS.append(char_imgs)

    return np.array(ALL_IMGS)
kdtree.py 文件源码 项目:pykdgrav 作者: omgspace 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def GenerateChildren(self, axis):
        if self.IsLeaf:
            return False
        x = self.points[:,axis]
        med = (self.bounds[axis,0] + self.bounds[axis,1])/2
        index = (x<med)

        if np.any(index):
            self.left = KDNode(self.points[index], self.masses[index], self.softening[index])
            self.HasLeft = True
        index = np.invert(index)
        if np.any(index):
            self.right = KDNode(self.points[index],self.masses[index], self.softening[index])
            self.HasRight = True
        self.points = empty((1,1))
        self.masses = empty(1)
        self.softening = empty(1)
        return True
timit_for_srnn.py 文件源码 项目:srnn 作者: marcofraccaro 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def create_test_set(x_lst):
    n = len(x_lst)
    x_lens = np.array(map(len, x_lst))
    max_len = max(map(len, x_lst)) - 1
    u_out = np.zeros((n, max_len, OUTDIM), dtype='float32')*np.nan
    x_out = np.zeros((n, max_len, OUTDIM), dtype='float32')*np.nan
    for row, vec in enumerate(x_lst):
        l = len(vec) - 1
        u = vec[:-1]  # all but last element
        x = vec[1:]   # all but first element

        x_out[row, :l] = x
        u_out[row, :l] = u

    mask = np.invert(np.isnan(x_out))
    x_out[np.isnan(x_out)] = 0
    u_out[np.isnan(u_out)] = 0
    mask = mask[:, :, 0]
    assert np.all((mask.sum(axis=1)+1) == x_lens)
    return u_out, x_out, mask.astype('float32')
AverageOfAir_ExtendedMask.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def _get_air_voxels(self, input_data, border_offset=3):
        """Get a two dimensional list with all the voxels in the air.

        Returns:
            ndarray: The first dimension is the list of voxels, the second the signal per voxel.
        """
        indices = np.where(input_data.mask > 0)
        max_dims = np.max(indices, axis=1)
        min_dims = np.min(indices, axis=1)

        mask = np.copy(input_data.mask)

        mask[min_dims[0]:max_dims[0]] = True
        mask[:, min_dims[1]:max_dims[1], :] = True
        mask[..., min_dims[2]:max_dims[2]] = True

        mask[0:border_offset] = True
        mask[-border_offset:] = True
        mask[:, 0:border_offset, :] = True
        mask[:, -border_offset:, :] = True
        mask[..., 0:border_offset] = True
        mask[..., -border_offset:] = True

        return create_roi(input_data.signal4d, np.invert(mask))
AverageOfAir_DilatedMask.py 文件源码 项目:MDT 作者: cbclab 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def _get_air_voxels(self, input_data, border_offset=3):
        """Get a two dimensional list with all the voxels in the air.

        Returns:
            ndarray: The first dimension is the list of voxels, the second the signal per voxel.
        """
        mask = np.copy(input_data.mask)
        mask = binary_dilation(mask, iterations=1)

        mask[0:border_offset] = True
        mask[-border_offset:] = True
        mask[:, 0:border_offset, :] = True
        mask[:, -border_offset:, :] = True
        mask[..., 0:border_offset] = True
        mask[..., -border_offset:] = True

        return create_roi(input_data.signal4d, np.invert(mask))
post_assign.py 文件源码 项目:SVclone 作者: mcmero 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def fix_variant_number_discrepancy(var_df, var_filt_df, filt_ids, ccert_ids, ccert, snvs):
    n_to_assign = len(var_df)
    var_df = pd.concat([var_df, var_filt_df])

    var_in_ccert = np.array([var_id in ccert_ids for var_id in filt_ids])
    var_filt_df = var_filt_df[var_in_ccert]

    filt_ids = get_var_ids(var_filt_df, snvs)
    ccert_in_df = np.array([cc_id in filt_ids for cc_id in ccert_ids])
    ccert = ccert[ccert_in_df]

    to_assign = np.concatenate([ np.array([True] * n_to_assign, dtype=bool),
                                 np.invert(var_in_ccert) ])

    var_df.index = range(len(var_df))
    var_df = var_df[to_assign]
    return(var_df, var_filt_df, ccert)
app.py 文件源码 项目:mnist-flask 作者: akashdeepjassal 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def predict():
    # get data from drawing canvas and save as image
    parseImage(request.get_data())

    # read parsed image back in 8-bit, black and white mode (L)
    x = imread('output.png', mode='L')
    x = np.invert(x)
    x = imresize(x,(28,28))

    # reshape image data for use in neural network
    x = x.reshape(1,28,28,1)
    with graph.as_default():
        out = model.predict(x)
        print(out)
        print(np.argmax(out, axis=1))
        response = np.array_str(np.argmax(out, axis=1))
        return response
mask_retina.py 文件源码 项目:qtim_ROP 作者: QTIM-Lab 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def create_mask(im_arr, erode=0):

    if im_arr.shape[2] == 3:
        im_arr = rgb2gray(im_arr)

    thresh = 0.05
    inv_bin = np.invert(im_arr > thresh)
    all_labels = measure.label(inv_bin)

    # Select largest object and invert
    seg_arr = all_labels == 0

    if erode > 0:
        strel = selem.disk(erode, dtype=np.bool)
        seg_arr = binary_erosion(seg_arr, selem=strel)
    elif erode < 0:
        strel = selem.disk(abs(erode), dtype=np.bool)
        seg_arr = binary_dilation(seg_arr, selem=strel)

    return seg_arr.astype(np.bool)
proj.py 文件源码 项目:PyME 作者: vikramsunkara 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def plot_reg_2D_stoc(X,stoc_vector):

    deter_vec = np.invert(stoc_vector)

    dom_max = np.amax(X[stoc_vector,:]) + 1

    A = np.zeros((dom_max,dom_max))

    stoc_indexs = np.arange(0,X.shape[0],1)[stoc_vector].astype(int)

    for i,deter_element in enumerate(deter_vec):
        if deter_element == True:
            A[X[int(stoc_indexs[0]),:].astype(int), X[int(stoc_indexs[1]),:].astype(int)] = X[i,:]
            pl.figure(i)
            #ax = fig.gca(projection='3d')
            #surf = ax.plot_surface(X[int(stoc_indexs[0]),:].astype(int), X[int(stoc_indexs[1]),:].astype(int),X[i,:], rstride=1, cstride=1,
#cmap=cm.coolwarm,linewidth=0, antialiased=False)
            pl.contour(A,X[i,:])
            #ax.zaxis.set_major_locator(LinearLocator(10))
            #ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
            #fig.colorbar(surf, shrink=0.5, aspect=5)
            pl.show()
proj_v2.py 文件源码 项目:PyME 作者: vikramsunkara 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def plot_reg_2D_stoc(X,stoc_vector):

    deter_vec = np.invert(stoc_vector)

    dom_max = np.amax(X[stoc_vector,:]) + 1

    A = np.zeros((dom_max,dom_max))

    stoc_indexs = np.arange(0,X.shape[0],1)[stoc_vector].astype(int)

    for i,deter_element in enumerate(deter_vec):
        if deter_element == True:
            A[X[int(stoc_indexs[0]),:].astype(int), X[int(stoc_indexs[1]),:].astype(int)] = X[i,:]
            pl.figure(i)
            #ax = fig.gca(projection='3d')
            #surf = ax.plot_surface(X[int(stoc_indexs[0]),:].astype(int), X[int(stoc_indexs[1]),:].astype(int),X[i,:], rstride=1, cstride=1,
#cmap=cm.coolwarm,linewidth=0, antialiased=False)
            pl.contour(A,X[i,:])
            #ax.zaxis.set_major_locator(LinearLocator(10))
            #ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
            #fig.colorbar(surf, shrink=0.5, aspect=5)
            pl.show()
atari-qlearning.py 文件源码 项目:reinforcement-learning 作者: cgnicholls 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def train(sess, q_network, target_network, observations):
    # Sample a minibatch to train on
    mini_batch = random.sample(observations, MINI_BATCH_SIZE)

    states = [d['state'] for d in mini_batch]
    actions = [d['action'] for d in mini_batch]
    rewards = [d['reward'] for d in mini_batch]
    next_states = [d['next_state'] for d in mini_batch]
    terminal = np.array([d['terminal'] for d in mini_batch])

    # Compute Q(s', a'; theta'), where theta' are the parameters for the target
    # network. This is an unbiased estimator for y_i as in eqn 2 in the DQN
    # paper.
    next_q = sess.run(target_network.output_layer, feed_dict={
        target_network.input_layer: next_states
    })

    target_q = rewards + np.invert(terminal).astype('float32') * DISCOUNT_FACTOR * np.max(next_q, axis=1)

    one_hot_actions = compute_one_hot_actions(actions)

    # Train the q-network (i.e. the parameters theta).
    q_network.train(sess, states, one_hot_actions, target_q)

# Return a one hot vector with a 1 at the index for the action.
_cluster.py 文件源码 项目:ananke 作者: beiko-lab 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def normalize_simple(matrix, mask):
    """Normalizes a matrix by columns, and then by rows. With multiple
    time-series, the data are normalized to the within-series total, not the
    entire data set total.

    Parameters
    ----------
    matrix: np.matrix
        Time-series matrix of abundance counts. Rows are sequences, columns
        are samples/time-points.
    mask: list or np.array
        List of objects with length matching the number of timepoints, where
        unique values delineate multiple time-series. If there is only one
        time-series in the data set, it's a list of identical objects.

    Returns
    -------
    normal_matrix: np.matrix
        Matrix where the columns (within-sample) have been converted to 
        proportions, then the rows are normalized to sum to 1.
    """
    normal_matrix = matrix / matrix.sum(0)
    normal_matrix[np.invert(np.isfinite(normal_matrix))] = 0
    for mask_val in np.unique(mask):
        y = normal_matrix[:, np.where(mask == mask_val)[0]]
        y = np.apply_along_axis(zscore, 1, y)
        normal_matrix[:, np.where(mask == mask_val)[0]] = y
        del y
    return normal_matrix
app.py 文件源码 项目:how_to_deploy_a_keras_model_to_production 作者: llSourcell 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def predict():
    #whenever the predict method is called, we're going
    #to input the user drawn character as an image into the model
    #perform inference, and return the classification
    #get the raw data format of the image
    imgData = request.get_data()
    #encode it into a suitable format
    convertImage(imgData)
    print "debug"
    #read the image into memory
    x = imread('output.png',mode='L')
    #compute a bit-wise inversion so black becomes white and vice versa
    x = np.invert(x)
    #make it the right size
    x = imresize(x,(28,28))
    #imshow(x)
    #convert to a 4D tensor to feed into our model
    x = x.reshape(1,28,28,1)
    print "debug2"
    #in our computation graph
    with graph.as_default():
        #perform the prediction
        out = model.predict(x)
        print(out)
        print(np.argmax(out,axis=1))
        print "debug3"
        #convert the response to a string
        response = np.array_str(np.argmax(out,axis=1))
        return response
copula.py 文件源码 项目:mixedvines 作者: asnelt 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def _ccdf(self, samples):
        vals = np.zeros(samples.shape[0])
        # Avoid subtraction of infinities
        neqz = np.bitwise_and(np.any(samples > 0.0, axis=1),
                              np.any(samples < 1.0, axis=1))
        nrvs = norm.ppf(samples[neqz, :])
        vals[neqz] = norm.cdf((nrvs[:, 0] - self.theta * nrvs[:, 1])
                              / np.sqrt(1 - self.theta**2))
        vals[np.invert(neqz)] = norm.cdf(0.0)
        return vals
test_arraysetops.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 92 收藏 0 点赞 0 评论 0
def test_in1d_invert(self):
        "Test in1d's invert parameter"
        # We use two different sizes for the b array here to test the
        # two different paths in in1d().
        for mult in (1, 10):
            a = np.array([5, 4, 5, 3, 4, 4, 3, 4, 3, 5, 2, 1, 5, 5])
            b = [2, 3, 4] * mult
            assert_array_equal(np.invert(in1d(a, b)), in1d(a, b, invert=True))
arraysetops.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def setdiff1d(ar1, ar2, assume_unique=False):
    """
    Find the set difference of two arrays.

    Return the sorted, unique values in `ar1` that are not in `ar2`.

    Parameters
    ----------
    ar1 : array_like
        Input array.
    ar2 : array_like
        Input comparison array.
    assume_unique : bool
        If True, the input arrays are both assumed to be unique, which
        can speed up the calculation.  Default is False.

    Returns
    -------
    setdiff1d : ndarray
        Sorted 1D array of values in `ar1` that are not in `ar2`.

    See Also
    --------
    numpy.lib.arraysetops : Module with a number of other functions for
                            performing set operations on arrays.

    Examples
    --------
    >>> a = np.array([1, 2, 3, 2, 4, 1])
    >>> b = np.array([3, 4, 5, 6])
    >>> np.setdiff1d(a, b)
    array([1, 2])

    """
    if assume_unique:
        ar1 = np.asarray(ar1).ravel()
    else:
        ar1 = unique(ar1)
        ar2 = unique(ar2)
    return ar1[in1d(ar1, ar2, assume_unique=True, invert=True)]
test_extras.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_in1d_invert(self):
        # Test in1d's invert parameter
        a = array([1, 2, 5, 7, -1], mask=[0, 0, 0, 0, 1])
        b = array([1, 2, 3, 4, 5, -1], mask=[0, 0, 0, 0, 0, 1])
        assert_equal(np.invert(in1d(a, b)), in1d(a, b, invert=True))

        a = array([5, 5, 2, 1, -1], mask=[0, 0, 0, 0, 1])
        b = array([1, 5, -1], mask=[0, 0, 1])
        assert_equal(np.invert(in1d(a, b)), in1d(a, b, invert=True))

        assert_array_equal([], in1d([], [], invert=True))
fusion.py 文件源码 项目:cupy 作者: cupy 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __invert__(self):
        return invert(self)
testing_lib.py 文件源码 项目:magenta 作者: tensorflow 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def assert_set_equality(test_case, expected, actual):
  """Asserts that two lists are equal without order.

  Given two lists, treat them as sets and test equality. This function only
  requires an __eq__ method to be defined on the objects, and not __hash__
  which set comparison requires. This function removes the burden of defining
  a __hash__ method just for testing.

  This function calls into tf.test.TestCase.assert* methods and behaves
  like a test assert. The function returns if `expected` and `actual`
  contain the same objects regardless of ordering.

  Note, this is an O(n^2) operation and is not suitable for large lists.

  Args:
    test_case: A tf.test.TestCase instance from a test.
    expected: A list of objects.
    actual: A list of objects.
  """
  actual_found = np.zeros(len(actual), dtype=bool)
  for expected_obj in expected:
    found = False
    for i, actual_obj in enumerate(actual):
      if expected_obj == actual_obj:
        actual_found[i] = True
        found = True
        break
    if not found:
      test_case.fail('Expected %s not found in actual collection' %
                     expected_obj)
  if not np.all(actual_found):
    test_case.fail('Actual objects %s not found in expected collection' %
                   np.array(actual)[np.invert(actual_found)])
acc2_test.py 文件源码 项目:veros 作者: dionhaefner 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def set_initial_conditions(self):
        m = self.main_module

        # initial conditions
        m.temp[:, :, :, 0:2] = ((1 - m.zt[None, None, :] / m.zw[0]) * 15 * m.maskT)[..., None]
        m.salt[:, :, :, 0:2] = 35.0 * m.maskT[..., None]

        # wind stress forcing
        taux = np.zeros(m.ny + 1, dtype=self.default_float_type)
        yt = m.yt[2:m.ny + 3]
        taux = (.1e-3 * np.sin(np.pi * (m.yu[2:m.ny + 3] - yu_start) / (-20.0 - yt_start))) * (yt < -20) \
            + (.1e-3 * (1 - np.cos(2 * np.pi *
                                   (m.yu[2:m.ny + 3] - 10.0) / (yu_end - 10.0)))) * (yt > 10)
        m.surface_taux[:, 2:m.ny + 3] = taux * m.maskU[:, 2:m.ny + 3, -1]

        # surface heatflux forcing
        self.t_star = 15 * np.invert((m.yt < -20) | (m.yt > 20)) \
            + 15 * (m.yt - yt_start) / (-20 - yt_start) * (m.yt < -20) \
            + 15 * (1 - (m.yt - 20) / (yt_end - 20)) * (m.yt > 20.)
        self.t_rest = m.dzt[None, -1] / (30. * 86400.) * m.maskT[:, :, -1]

        t = self.tke_module
        if t.enable_tke:
            t.forc_tke_surface[2:-2, 2:-2] = np.sqrt((0.5 * (m.surface_taux[2:-2, 2:-2] + m.surface_taux[1:-3, 2:-2]))**2
                                                     + (0.5 * (m.surface_tauy[2:-2, 2:-2] + m.surface_tauy[2:-2, 1:-3]))**2)**(1.5)

        i = self.idemix_module
        if i.enable_idemix:
            i.forc_iw_bottom[:] = 1.0e-6 * m.maskW[:, :, -1]
            i.forc_iw_surface[:] = 0.1e-6 * m.maskW[:, :, -1]
signature_genes.py 文件源码 项目:CS-SMAF 作者: brian-cleary 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def signature_predictions(X0,n_test_samples,n_signatures):
    sidx = np.zeros(X0.shape[1],dtype=np.bool)
    sidx[:n_test_samples] = True
    np.random.shuffle(sidx)
    Xtrain = X0[:,np.invert(sidx)]
    Xtest = X0[:,sidx]
    sg = get_signature_genes(Xtrain,n_signatures,lda=10000000)
    model = build_signature_model(Xtrain,sg)
    Xhat = (model.predict(Xtest[sg].T)).T
    return sg,Xtest,Xhat
charades.py 文件源码 项目:actions-for-actions 作者: gsig 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def compute_scores(self):
        m_aps = []
        for oc_i in range(self.n_classes):
            sorted_idxs = np.argsort(- self.submission_array[:, oc_i])
            tp = self.gt_array[:, oc_i][sorted_idxs] == 1
            fp = np.invert(tp)
            n_pos = tp.sum()
            if n_pos < 0.1:
                m_aps.append(float('nan'))
                continue
            n_neg = fp.sum()
            f_pcs = np.cumsum(fp)
            t_pcs = np.cumsum(tp)
            prec = t_pcs / (f_pcs + t_pcs)
            if self.normalize_map:
                k = self.N_all/n_pos
                k2 = self.F_all/n_neg
                prec=(t_pcs*k) / (f_pcs*k2+t_pcs*k)
            avg_prec = 0
            for i in range(self.submission_array.shape[0]):
                if tp[i]:
                    avg_prec += prec[i]
            m_aps.append(avg_prec / n_pos)
        m_aps = np.array(m_aps)
        m_ap = np.mean(m_aps)
        w_ap = (m_aps * self.gt_array.sum(axis=0) / self.gt_array.sum()).sum()
        return m_ap, w_ap, m_aps
doom_simulator.py 文件源码 项目:DirectFuturePrediction 作者: IntelVCL 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def analyze_controls(self, config_file):
        with open(config_file, 'r') as myfile:
            config = myfile.read()
        m = re.search('available_buttons[\s]*\=[\s]*\{([^\}]*)\}', config)
        avail_controls = m.group(1).split()
        cont_controls = np.array([bool(re.match('.*_DELTA', c)) for c in avail_controls])
        discr_controls = np.invert(cont_controls)
        return avail_controls, np.squeeze(np.nonzero(cont_controls)), np.squeeze(np.nonzero(discr_controls))
filters.py 文件源码 项目:myreco 作者: dutradda 项目源码 文件源码 阅读 39 收藏 0 点赞 0 评论 0
def _filter(self, filter_, items_vector):
        if not self.is_inclusive:
            filter_ = np.invert(filter_)

        items_vector *= filter_
test_arraysetops.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def test_in1d_invert(self):
        "Test in1d's invert parameter"
        # We use two different sizes for the b array here to test the
        # two different paths in in1d().
        for mult in (1, 10):
            a = np.array([5, 4, 5, 3, 4, 4, 3, 4, 3, 5, 2, 1, 5, 5])
            b = [2, 3, 4] * mult
            assert_array_equal(np.invert(in1d(a, b)), in1d(a, b, invert=True))
arraysetops.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def setdiff1d(ar1, ar2, assume_unique=False):
    """
    Find the set difference of two arrays.

    Return the sorted, unique values in `ar1` that are not in `ar2`.

    Parameters
    ----------
    ar1 : array_like
        Input array.
    ar2 : array_like
        Input comparison array.
    assume_unique : bool
        If True, the input arrays are both assumed to be unique, which
        can speed up the calculation.  Default is False.

    Returns
    -------
    setdiff1d : ndarray
        Sorted 1D array of values in `ar1` that are not in `ar2`.

    See Also
    --------
    numpy.lib.arraysetops : Module with a number of other functions for
                            performing set operations on arrays.

    Examples
    --------
    >>> a = np.array([1, 2, 3, 2, 4, 1])
    >>> b = np.array([3, 4, 5, 6])
    >>> np.setdiff1d(a, b)
    array([1, 2])

    """
    if assume_unique:
        ar1 = np.asarray(ar1).ravel()
    else:
        ar1 = unique(ar1)
        ar2 = unique(ar2)
    return ar1[in1d(ar1, ar2, assume_unique=True, invert=True)]
test_extras.py 文件源码 项目:krpcScripts 作者: jwvanderbeck 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def test_in1d_invert(self):
        # Test in1d's invert parameter
        a = array([1, 2, 5, 7, -1], mask=[0, 0, 0, 0, 1])
        b = array([1, 2, 3, 4, 5, -1], mask=[0, 0, 0, 0, 0, 1])
        assert_equal(np.invert(in1d(a, b)), in1d(a, b, invert=True))

        a = array([5, 5, 2, 1, -1], mask=[0, 0, 0, 0, 1])
        b = array([1, 5, -1], mask=[0, 0, 1])
        assert_equal(np.invert(in1d(a, b)), in1d(a, b, invert=True))

        assert_array_equal([], in1d([], [], invert=True))
two_point_functions.py 文件源码 项目:yt 作者: yt-project 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def _bin_results(self, length, results):
        """
        Add hits to the bins corresponding to these results. length_hit_bins
        is flattened, so we need to figure out the offset for this hit by
        factoring the sizes of the other dimensions.
        """
        hit_bin = np.zeros(results.shape[0], dtype='int64')
        multi = 1
        good = np.ones(results.shape[0], dtype='bool')
        for dim in range(len(self.out_labels)):
            for d1 in range(dim):
                multi *= self.bin_edges[d1].size
            if dim == 0 and len(self.out_labels)==1:
                try:
                    digi = np.digitize(results, self.bin_edges[dim])
                except ValueError:
                    # The user probably did something like 
                    # return a * b rather than
                    # return a[0] * b[0], which will only happen
                    # for single field functions.
                    digi = np.digitize(results[0], self.bin_edges[dim])
            else:
                digi = np.digitize(results[:,dim], self.bin_edges[dim])
            too_low = (digi == 0)
            too_high = (digi == self.bin_edges[dim].size)
            self.too_low[dim] += (too_low).sum()
            self.too_high[dim] += (too_high).sum()
            newgood = np.bitwise_and(np.invert(too_low), np.invert(too_high))
            good = np.bitwise_and(good, newgood)
            hit_bin += np.multiply((digi - 1), multi)
        digi_bins = np.arange(self.length_bin_hits[length].size+1)
        hist, digi_bins = np.histogram(hit_bin[good], digi_bins)
        self.length_bin_hits[length] += hist


问题


面经


文章

微信
公众号

扫码关注公众号