python类pad()的实例源码

utils.py 文件源码 项目:aapm_thoracic_challenge 作者: xf4j 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def restore_labels(labels, roi, read_info):
    if roi == -1:
        # Pad first, then resize to original shape
        labels = np.pad(labels, ((0, 0), (CROP, CROP), (CROP, CROP)), 'constant')
        restored_labels = np.zeros(read_info['shape'], dtype=np.float32)
        for z in range(N_CLASSES):
            roi = resize((labels == z + 1).astype(np.float32), read_info['shape'], mode='constant')
            roi[roi >= 0.5] = 1
            roi[roi < 0.5] = 0
            roi = clean_contour(roi, is_prob=False)
            restored_labels[roi == 1] = z + 1
    else:
        labels = clean_contour(labels, is_prob=True)
        # Resize to extracted shape, then pad to original shape
        labels = resize(labels, read_info['extract_shape'], mode='constant')
        restored_labels = np.zeros(read_info['shape'], dtype=np.float32)
        extract = read_info['extract']
        restored_labels[extract[0][0] : extract[0][1], extract[1][0] : extract[1][1], extract[2][0] : extract[2][1]] = labels
    return restored_labels
visualisation.py 文件源码 项目:bnn-analysis 作者: myshkov 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def plot_hist(baseline_samples, target_samples, true_x, true_y):
    baseline_samples = baseline_samples.squeeze()
    target_samples = target_samples.squeeze()

    bmin, bmax = baseline_samples.min(), baseline_samples.max()

    ax = sns.kdeplot(baseline_samples, shade=True, color=(0.6, 0.1, 0.1, 0.2))
    ax = sns.kdeplot(target_samples, shade=True, color=(0.1, 0.1, 0.6, 0.2))
    ax.set_xlim(bmin, bmax)

    y0, y1 = ax.get_ylim()

    plt.plot([true_y, true_y], [0, y1 - (y1 - y0) * 0.01], linewidth=1, color='r')
    plt.title('Predictive' + (f' at {true_x:.2f}' if true_x is not None else ''))

    fig = plt.gcf()
    fig.set_size_inches(9, 9)
    # plt.tight_layout()  # pad=0.4, w_pad=0.5, h_pad=1.0)

    name = utils.DATA_DIR.replace('/', '-')
    # plt.tight_layout(pad=0.6)
    utils.save_fig('predictive-at-point-' + name)
data_input.py 文件源码 项目:ResNet-deeplabV3 作者: Harvey1973 项目源码 文件源码 阅读 46 收藏 0 点赞 0 评论 0
def prepare_train_data(padding_size):
    '''
    Read all the train data into numpy array and add padding_size of 0 paddings on each side of the
    image
    :param padding_size: int. how many layers of zero pads to add on each side?
    :return: all the train data and corresponding labels
    '''
    path_list = []
    for i in range(1, NUM_TRAIN_BATCH+1):
        path_list.append(full_data_dir + str(i))
    data, label = read_in_all_images(path_list)

    pad_width = ((0, 0), (padding_size, padding_size), (padding_size, padding_size), (0, 0))
    data = np.pad(data, pad_width=pad_width, mode='constant', constant_values=0)

    return data, label
basic_model.py 文件源码 项目:sea-lion-counter 作者: rdinse 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def generateCountMaps(self, coords):
    '''Generates a count map for the provided list of coordinates.  It can
    count at most 256 object within the receptive field.  Beyond that it
    overflows.
    '''

    s = self.config['receptive_field_size']
    pad = s // 2
    unpadded_size = self.config['tile_size']
    target_size = 1 + unpadded_size + 2 * pad
    countMaps = np.zeros((self.config['cls_nb'], target_size, target_size), dtype=np.int16)

    y_min = 0
    y_max = unpadded_size
    x_min = 0
    x_max = unpadded_size
    for coord in coords:
      if coord[1] >= y_min and coord[1] < y_max and coord[2] >= x_min and coord[2] < x_max:
        self.inc_region(countMaps[coord[0]], coord[1] + pad, coord[2] + pad, s, s)

    return np.moveaxis(countMaps, 0, -1).astype(np.float32)
data_loader_test.py 文件源码 项目:segmentation_DLMI 作者: imatge-upc 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def load_ROI_mask(self):

        proxy = nib.load(self.FLAIR_FILE)
        image_array = np.asarray(proxy.dataobj)

        mask = np.ones_like(image_array)
        mask[np.where(image_array < 90)] = 0

        # img = nib.Nifti1Image(mask, proxy.affine)
        # nib.save(img, join(modalities_path,'mask.nii.gz'))

        struct_element_size = (20, 20, 20)
        mask_augmented = np.pad(mask, [(21, 21), (21, 21), (21, 21)], 'constant', constant_values=(0, 0))
        mask_augmented = binary_closing(mask_augmented, structure=np.ones(struct_element_size, dtype=bool)).astype(
            np.int)

        return mask_augmented[21:-21, 21:-21, 21:-21].astype('bool')
preprocessing.py 文件源码 项目:segmentation_DLMI 作者: imatge-upc 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def resize_image(image,target_shape, pad_value = 0):
    assert isinstance(target_shape, list) or isinstance(target_shape, tuple)
    add_shape, subs_shape = [], []

    image_shape = image.shape
    shape_difference = np.asarray(target_shape, dtype=int) - np.asarray(image_shape,dtype=int)
    for diff in shape_difference:
        if diff < 0:
            subs_shape.append(np.s_[int(np.abs(np.ceil(diff/2))):int(np.floor(diff/2))])
            add_shape.append((0, 0))
        else:
            subs_shape.append(np.s_[:])
            add_shape.append((int(np.ceil(1.0*diff/2)),int(np.floor(1.0*diff/2))))
    output = np.pad(image, tuple(add_shape), 'constant', constant_values=(pad_value, pad_value))
    output = output[subs_shape]
    return output
nettrainer.py 文件源码 项目:deep-prior 作者: moberweger 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def alignData(self, data):
        """
        Align data to a multiple of the macro batch size, pad last incomplete minibatch with random samples
        :param data: data for alignment
        :return: padded data
        """
        # pad with zeros to macro batch size, but only along dimension 0 ie samples
        topad = self.getNumSamplesPerMacroBatch() - data.shape[0] % self.getNumSamplesPerMacroBatch()
        sz = []
        sz.append((0, topad))
        for i in range(len(data.shape) - 1):
            sz.append((0, 0))
        padded = numpy.pad(data, sz, mode='constant', constant_values=0)

        # fill last incomplete minibatch with random samples
        if (data.shape[0] % self.cfgParams.batch_size) != 0:
            # start from same random seed every time the data is padded, otherwise labels and data mix up
            rng = numpy.random.RandomState(data.shape[0])
            for i in xrange(0, self.cfgParams.batch_size - (data.shape[0] % self.cfgParams.batch_size)):
                padded[data.shape[0]+i] = padded[rng.randint(0, data.shape[0])]
        return padded
test_cnn.py 文件源码 项目:CNN_denoise 作者: weedwind 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def org_data(utt_feat, win_size_before, win_size_after):
   frm_num, feat_dim = utt_feat.shape
   width = win_size_before + win_size_after + 1

   out_feat = np.zeros((frm_num, 1, feat_dim, width))

   utt_feat = np.pad(utt_feat, ((win_size_before, win_size_after), (0,0)), mode = 'edge')    # pad the starting and ending frames

   for i in range(frm_num):
      frm_idx = i + win_size_before
      block_data = utt_feat[frm_idx - win_size_before : frm_idx + win_size_after + 1, :]

      block_data = block_data.T
      block_data = block_data.reshape(1, block_data.shape[0], block_data.shape[1])

      out_feat[i] = block_data

   return out_feat
vis.py 文件源码 项目:DeepTextSpotter 作者: MichalBusta 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def vis_square(data):
    """Take an array of shape (n, height, width) or (n, height, width, 3)
       and visualize each (height, width) thing in a grid of size approx. sqrt(n) by sqrt(n)"""

    # normalize data for display
    data = (data - data.min()) / (data.max() - data.min())

    # force the number of filters to be square
    n = int(np.ceil(np.sqrt(data.shape[0])))
    padding = (((0, n ** 2 - data.shape[0]),
               (0, 1), (0, 1))                 # add some space between filters
               + ((0, 0),) * (data.ndim - 3))  # don't pad the last dimension (if there is one)
    data = np.pad(data, padding, mode='constant', constant_values=1)  # pad with ones (white)

    # tile the filters into an image
    data = data.reshape((n, n) + data.shape[1:]).transpose((0, 2, 1, 3) + tuple(range(4, data.ndim + 1)))
    data = data.reshape((n * data.shape[1], n * data.shape[3]) + data.shape[4:])
    plt.imshow(data, interpolation='nearest'); plt.axis('off')
artificial.py 文件源码 项目:circletracking 作者: caspervdw 项目源码 文件源码 阅读 42 收藏 0 点赞 0 评论 0
def crop_pad(image, corner, shape):
    ndim = len(corner)
    corner = [int(round(c)) for c in corner]
    shape = [int(round(s)) for s in shape]
    original = image.shape[-ndim:]
    zipped = zip(corner, shape, original)

    if np.any(c < 0 or c + s > o for (c, s, o) in zipped):
        no_padding = [(0, 0)] * (image.ndim - ndim)
        padding = [(max(-c, 0), max(c + s - o, 0)) for (c, s, o) in zipped]
        corner = [c + max(-c, 0) for c in corner]
        image_temp = np.pad(image, no_padding + padding, mode=str('constant'))
    else:
        image_temp = image

    no_crop = [slice(o+1) for o in image.shape[:-ndim]]
    crop = [slice(c, c+s) for (c, s) in zip(corner, shape)]
    return image_temp[no_crop + crop]
fttools.py 文件源码 项目:prysm 作者: brandondube 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def pad2d(array, factor=1, value=0):
    ''' Symmetrically pads a 2D array with a value.

    Args:
        array (`numpy.ndarray`): source array.

        factor (`number`): number of widths of source array to add to each side (L/R/U/D).

        value (`number`): value with which to pad the array.

    Returns
        `numpy.ndarray`: padded array.

    '''
    x, y = array.shape
    pad_shape = ((int(x * factor), int(x * factor)), (int(y * factor), int(y * factor)))
    return np.pad(array, pad_width=pad_shape, mode='constant', constant_values=value)
deeplab.py 文件源码 项目:train-DeepLab 作者: martinkersner 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def preprocess_image(img_path, img_size):
  if not os.path.exists(img_path):
    print(img_path)
    return None, 0, 0

  input_image = 255 * caffe.io.load_image(img_path)

  image = PILImage.fromarray(np.uint8(input_image))
  image = np.array(image)

  mean_vec = np.array([103.939, 116.779, 123.68], dtype=np.float32)
  reshaped_mean_vec = mean_vec.reshape(1, 1, 3);
  preprocess_img = image[:,:,::-1]
  preprocess_img = preprocess_img - reshaped_mean_vec

  # Pad as necessary
  cur_h, cur_w, cur_c = preprocess_img.shape
  pad_h = img_size - cur_h
  pad_w = img_size - cur_w
  preprocess_img = np.pad(preprocess_img, pad_width=((0, pad_h), (0, pad_w), (0, 0)), mode = 'constant', constant_values = 0)

  return preprocess_img, cur_h, cur_w
gdae_dsd.py 文件源码 项目:mlsp2017_svsep_skipfilt 作者: Js-Mim 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def prepare_olapsequences(ms, vs, lsize, olap, bsize):
    from numpy.lib import stride_tricks
    global trimframe
    trimframe = ms.shape[0] % (lsize - olap)
    print(trimframe)
    if trimframe != 0:
        ms = np.pad(ms, ((0,trimframe), (0,0)), 'constant', constant_values=(0,0))
        vs = np.pad(vs, ((0,trimframe), (0,0)), 'constant', constant_values=(0,0))

    ms = stride_tricks.as_strided(ms, shape=(ms.shape[0] / (lsize - olap), lsize, ms.shape[1]),
                             strides=(ms.strides[0] * (lsize - olap), ms.strides[0], ms.strides[1]))
    ms = ms[:-1, :, :]

    vs = stride_tricks.as_strided(vs, shape=(vs.shape[0] / (lsize - olap), lsize, vs.shape[1]),
                                  strides=(vs.strides[0] * (lsize - olap), vs.strides[0], vs.strides[1]))
    vs = vs[:-1, :, :]

    btrimframe = (ms.shape[0] % bsize)
    if btrimframe != 0:
        ms = ms[:-btrimframe, :, :]
        vs = vs[:-btrimframe, :, :]

    #print(ms.max(), ms.min(), vs.max(), vs.min())
    #print(ms.shape, vs.shape)
    return ms, vs
b3_data_iter.py 文件源码 项目:kaggle-dstl-satellite-imagery-feature-detection 作者: u1234x1234 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def rel_crop(im, rel_cx, rel_cy, crop_size):

    map_size = im.shape[1]
    r = crop_size / 2
    abs_cx = rel_cx * map_size
    abs_cy = rel_cy * map_size
    na = np.floor([abs_cy-r, abs_cy+r, abs_cx-r, abs_cx+r]).astype(np.int32)
    a = np.clip(na, 0, map_size)
    px0 = a[2] - na[2]
    px1 = na[3] - a[3]
    py0 = a[0] - na[0]
    py1 = na[1] - a[1]
    crop = im[a[0]:a[1], a[2]:a[3]]
    crop = np.pad(crop, ((py0, py1), (px0, px1), (0, 0)),
                  mode='reflect')

    assert crop.shape == (crop_size, crop_size, im.shape[2])
    return crop
test_preprocessing.py 文件源码 项目:nnmnkwii 作者: r9y9 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def test_adjast_frame_length_divisible():
    D = 5
    T = 10

    x = np.random.rand(T, D)
    assert T == adjast_frame_length(x, pad=True, divisible_by=1).shape[0]
    assert T == adjast_frame_length(x, pad=True, divisible_by=2).shape[0]
    print(adjast_frame_length(x, pad=True, divisible_by=3).shape[0])
    assert T + 2 == adjast_frame_length(x, pad=True, divisible_by=3).shape[0]
    assert T + 2 == adjast_frame_length(x, pad=True, divisible_by=4).shape[0]

    assert T == adjast_frame_length(x, pad=False, divisible_by=1).shape[0]
    assert T == adjast_frame_length(x, pad=False, divisible_by=2).shape[0]
    assert T - 1 == adjast_frame_length(x, pad=False, divisible_by=3).shape[0]
    assert T - 2 == adjast_frame_length(x, pad=False, divisible_by=4).shape[0]

    # Should preserve dtype
    for dtype in [np.float32, np.float64]:
        x = np.random.rand(T, D).astype(dtype)
        assert x.dtype == adjast_frame_length(x, pad=True, divisible_by=3).dtype
        assert x.dtype == adjast_frame_length(x, pad=False, divisible_by=3).dtype
__init__.py 文件源码 项目:latplan 作者: guicho271828 项目源码 文件源码 阅读 35 收藏 0 点赞 0 评论 0
def prepare_binary_classification_data(real, fake):
    import numpy as np
    shape = real.shape[1:]

    both = np.concatenate((real, fake),axis=0)
    both = np.reshape(both, (len(both), -1)) # flatten

    data_dim = both.shape[1]

    both2 = np.pad(both, ((0,0),(0,1)), 'constant') # default 0
    both2[:len(real),-1] = 1                        # tag true
    np.random.shuffle(both2)

    train_in  = np.reshape(both2[:int(0.9*len(both2)), :data_dim], (-1, *shape))
    train_out = both2[:int(0.9*len(both2)), -1]
    test_in   = np.reshape(both2[int(0.9*len(both2)):, :data_dim], (-1, *shape))
    test_out  = both2[int(0.9*len(both2)):, -1]

    return train_in, train_out, test_in, test_out
utils.py 文件源码 项目:tf-sr-zoo 作者: MLJejuCamp2017 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def imgread(img_path, scale = 4):
    img = scipy.misc.imread(img_path)
    img = img /256.0
    h,w,c = img.shape
    tmp1 = h % scale
    new_h = h + scale - tmp1
    tmp2 = w % scale
    new_w = w +scale-tmp2
    img = np.pad(img, ((0,scale-tmp1), (0, scale-tmp2),(0,0)), mode = 'reflect')
    if scale != None:
        img = np.expand_dims(img,0)
        img = tf.convert_to_tensor(img)
        lr_w = new_w / scale
        lr_h = new_h /scale
        img = tf.cast(img, tf.float32)
        img_lr = tf.image.resize_images(img, [lr_h, lr_w])
        img_lr = tf.cast(img_lr,tf.float32)
        return img_lr, img
    return img
utils.py 文件源码 项目:tf-sr-zoo 作者: MLJejuCamp2017 项目源码 文件源码 阅读 75 收藏 0 点赞 0 评论 0
def imgread(img_path, scale = 4):
    img = scipy.misc.imread(img_path)
    #img = scipy.misc.imresize(img, (128, 128))
    img = img /256.0
    h,w,c = img.shape
    new_h = pow(2, int(math.log(h, 2))+1)
    tmp1 = new_h - h 
    new_w = pow(2, int(math.log(w, 2))+1)
    tmp2 = new_w - w
    img = np.pad(img, ((0,tmp1), (0, tmp2),(0,0)), mode = 'constant')
    if scale != None:
        img = np.expand_dims(img,0)
        img = tf.convert_to_tensor(img)
        lr_w = new_w / scale
        lr_h = new_h /scale
        img = tf.cast(img, tf.float32)
        img_lr = tf.image.resize_images(img, [lr_h, lr_w])
        img_lr = tf.cast(img_lr,tf.float32)
        return img_lr, img
    return img
spatial_convolution.py 文件源码 项目:PyFunt 作者: dnlcrl 项目源码 文件源码 阅读 31 收藏 0 点赞 0 评论 0
def update_grad_input(self, input, grad_output, scale=1):
        x_shape, x_cols = self.x_shape, self.x_cols
        w = self.weight

        stride, pad = self.dW, self.padW

        N, C, H, W = x_shape
        F, _, HH, WW = w.shape
        _, _, out_h, out_w = grad_output.shape

        self.grad_bias[:] = np.sum(grad_output, axis=(0, 2, 3))[:]

        dout_reshaped = grad_output.transpose(1, 0, 2, 3).reshape(F, -1)
        self.grad_weight[:] = dout_reshaped.dot(x_cols.T).reshape(w.shape)[:]

        dx_cols = w.reshape(F, -1).T.dot(dout_reshaped)
        #dx_cols.shape = (C, HH, WW, N, out_h, out_w)
        # dx = col2im_6d_cython(dx_cols, N, C, H, W, HH, WW, pad, stride)
        dx = col2im_cython(dx_cols, N, C, H, W, HH, WW, pad, stride)
        self.grad_input = dx
        return dx
test_arraypad.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def test_zero_padding_shortcuts(self):
        test = np.arange(120).reshape(4, 5, 6)
        pad_amt = [(0, 0) for axis in test.shape]
        modes = ['constant',
                 'edge',
                 'linear_ramp',
                 'maximum',
                 'mean',
                 'median',
                 'minimum',
                 'reflect',
                 'symmetric',
                 'wrap',
                 ]
        for mode in modes:
            assert_array_equal(test, pad(test, pad_amt, mode=mode))
test_arraypad.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def test_check_mean_stat_length(self):
        a = np.arange(100).astype('f')
        a = pad(a, ((25, 20), ), 'mean', stat_length=((2, 3), ))
        b = np.array(
            [0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
             0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5,
             0.5, 0.5, 0.5, 0.5, 0.5,

             0., 1., 2., 3., 4., 5., 6., 7., 8., 9.,
             10., 11., 12., 13., 14., 15., 16., 17., 18., 19.,
             20., 21., 22., 23., 24., 25., 26., 27., 28., 29.,
             30., 31., 32., 33., 34., 35., 36., 37., 38., 39.,
             40., 41., 42., 43., 44., 45., 46., 47., 48., 49.,
             50., 51., 52., 53., 54., 55., 56., 57., 58., 59.,
             60., 61., 62., 63., 64., 65., 66., 67., 68., 69.,
             70., 71., 72., 73., 74., 75., 76., 77., 78., 79.,
             80., 81., 82., 83., 84., 85., 86., 87., 88., 89.,
             90., 91., 92., 93., 94., 95., 96., 97., 98., 99.,

             98., 98., 98., 98., 98., 98., 98., 98., 98., 98.,
             98., 98., 98., 98., 98., 98., 98., 98., 98., 98.
             ])
        assert_array_equal(a, b)
test_arraypad.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 41 收藏 0 点赞 0 评论 0
def test_check_maximum_1(self):
        a = np.arange(100)
        a = pad(a, (25, 20), 'maximum')
        b = np.array(
            [99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
             99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
             99, 99, 99, 99, 99,

             0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
             10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
             20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
             30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
             40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
             50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
             60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
             70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
             80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
             90, 91, 92, 93, 94, 95, 96, 97, 98, 99,

             99, 99, 99, 99, 99, 99, 99, 99, 99, 99,
             99, 99, 99, 99, 99, 99, 99, 99, 99, 99]
            )
        assert_array_equal(a, b)
test_arraypad.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_check_maximum_stat_length(self):
        a = np.arange(100) + 1
        a = pad(a, (25, 20), 'maximum', stat_length=10)
        b = np.array(
            [10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
             10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
             10, 10, 10, 10, 10,

              1,  2,  3,  4,  5,  6,  7,  8,  9, 10,
             11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
             21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
             31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
             41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
             51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
             61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
             71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
             81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
             91, 92, 93, 94, 95, 96, 97, 98, 99, 100,

             100, 100, 100, 100, 100, 100, 100, 100, 100, 100,
             100, 100, 100, 100, 100, 100, 100, 100, 100, 100]
            )
        assert_array_equal(a, b)
test_arraypad.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_check_minimum_1(self):
        a = np.arange(100)
        a = pad(a, (25, 20), 'minimum')
        b = np.array(
            [0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
             0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
             0, 0, 0, 0, 0,

             0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
             10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
             20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
             30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
             40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
             50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
             60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
             70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
             80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
             90, 91, 92, 93, 94, 95, 96, 97, 98, 99,

             0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
             0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
            )
        assert_array_equal(a, b)
test_arraypad.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def test_check_minimum_2(self):
        a = np.arange(100) + 2
        a = pad(a, (25, 20), 'minimum')
        b = np.array(
            [2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
             2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
             2, 2, 2, 2, 2,

             2, 3, 4, 5, 6, 7, 8, 9, 10, 11,
             12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
             22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
             32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
             42, 43, 44, 45, 46, 47, 48, 49, 50, 51,
             52, 53, 54, 55, 56, 57, 58, 59, 60, 61,
             62, 63, 64, 65, 66, 67, 68, 69, 70, 71,
             72, 73, 74, 75, 76, 77, 78, 79, 80, 81,
             82, 83, 84, 85, 86, 87, 88, 89, 90, 91,
             92, 93, 94, 95, 96, 97, 98, 99, 100, 101,

             2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
             2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
            )
        assert_array_equal(a, b)
test_arraypad.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 34 收藏 0 点赞 0 评论 0
def test_check_minimum_stat_length(self):
        a = np.arange(100) + 1
        a = pad(a, (25, 20), 'minimum', stat_length=10)
        b = np.array(
            [ 1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
              1,  1,  1,  1,  1,  1,  1,  1,  1,  1,
              1,  1,  1,  1,  1,

              1,  2,  3,  4,  5,  6,  7,  8,  9, 10,
             11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
             21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
             31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
             41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
             51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
             61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
             71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
             81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
             91, 92, 93, 94, 95, 96, 97, 98, 99, 100,

             91, 91, 91, 91, 91, 91, 91, 91, 91, 91,
             91, 91, 91, 91, 91, 91, 91, 91, 91, 91]
            )
        assert_array_equal(a, b)
test_arraypad.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 37 收藏 0 点赞 0 评论 0
def test_check_median(self):
        a = np.arange(100).astype('f')
        a = pad(a, (25, 20), 'median')
        b = np.array(
            [49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5,
             49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5,
             49.5, 49.5, 49.5, 49.5, 49.5,

             0., 1., 2., 3., 4., 5., 6., 7., 8., 9.,
             10., 11., 12., 13., 14., 15., 16., 17., 18., 19.,
             20., 21., 22., 23., 24., 25., 26., 27., 28., 29.,
             30., 31., 32., 33., 34., 35., 36., 37., 38., 39.,
             40., 41., 42., 43., 44., 45., 46., 47., 48., 49.,
             50., 51., 52., 53., 54., 55., 56., 57., 58., 59.,
             60., 61., 62., 63., 64., 65., 66., 67., 68., 69.,
             70., 71., 72., 73., 74., 75., 76., 77., 78., 79.,
             80., 81., 82., 83., 84., 85., 86., 87., 88., 89.,
             90., 91., 92., 93., 94., 95., 96., 97., 98., 99.,

             49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5,
             49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5]
            )
        assert_array_equal(a, b)
test_arraypad.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 33 收藏 0 点赞 0 评论 0
def test_check_median_stat_length(self):
        a = np.arange(100).astype('f')
        a[1] = 2.
        a[97] = 96.
        a = pad(a, (25, 20), 'median', stat_length=(3, 5))
        b = np.array(
            [ 2.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,
              2.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,  2.,
              2.,  2.,  2.,  2.,  2.,

              0.,  2.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.,
             10., 11., 12., 13., 14., 15., 16., 17., 18., 19.,
             20., 21., 22., 23., 24., 25., 26., 27., 28., 29.,
             30., 31., 32., 33., 34., 35., 36., 37., 38., 39.,
             40., 41., 42., 43., 44., 45., 46., 47., 48., 49.,
             50., 51., 52., 53., 54., 55., 56., 57., 58., 59.,
             60., 61., 62., 63., 64., 65., 66., 67., 68., 69.,
             70., 71., 72., 73., 74., 75., 76., 77., 78., 79.,
             80., 81., 82., 83., 84., 85., 86., 87., 88., 89.,
             90., 91., 92., 93., 94., 95., 96., 96., 98., 99.,

             96., 96., 96., 96., 96., 96., 96., 96., 96., 96.,
             96., 96., 96., 96., 96., 96., 96., 96., 96., 96.]
            )
        assert_array_equal(a, b)
test_arraypad.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_check_mean_shape_one(self):
        a = [[4, 5, 6]]
        a = pad(a, (5, 7), 'mean', stat_length=2)
        b = np.array(
            [[4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6],
             [4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6],
             [4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6],
             [4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6],
             [4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6],

             [4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6],

             [4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6],
             [4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6],
             [4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6],
             [4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6],
             [4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6],
             [4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6],
             [4, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 6, 6, 6]]
            )
        assert_array_equal(a, b)
test_arraypad.py 文件源码 项目:radar 作者: amoose136 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def test_check_mean_2(self):
        a = np.arange(100).astype('f')
        a = pad(a, (25, 20), 'mean')
        b = np.array(
            [49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5,
             49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5,
             49.5, 49.5, 49.5, 49.5, 49.5,

             0., 1., 2., 3., 4., 5., 6., 7., 8., 9.,
             10., 11., 12., 13., 14., 15., 16., 17., 18., 19.,
             20., 21., 22., 23., 24., 25., 26., 27., 28., 29.,
             30., 31., 32., 33., 34., 35., 36., 37., 38., 39.,
             40., 41., 42., 43., 44., 45., 46., 47., 48., 49.,
             50., 51., 52., 53., 54., 55., 56., 57., 58., 59.,
             60., 61., 62., 63., 64., 65., 66., 67., 68., 69.,
             70., 71., 72., 73., 74., 75., 76., 77., 78., 79.,
             80., 81., 82., 83., 84., 85., 86., 87., 88., 89.,
             90., 91., 92., 93., 94., 95., 96., 97., 98., 99.,

             49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5,
             49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5, 49.5]
            )
        assert_array_equal(a, b)


问题


面经


文章

微信
公众号

扫码关注公众号