精华内容
下载资源
问答
  • randint
    2022-04-15 01:05:13

    np.random.randint(low, high=None, size=None, dtype=’l’) (return a range of intergers with low or high bounds)
    Return random integers from low (inclusive) to high (exclusive). the specified dtype in the “half-open” interval [low, high). If
    high is None (the default), then results are from [0, low).
    range范围前闭后开 [low, high) 或 [0, low)

    random.randint(a, b)
    Return random integer in range [a, b], including both end points.(return an integer)
    range范围 前闭后闭 [a, b]

    np.random.randint() 作为numpy库的一种方法,参数更丰富,相比于ranom.randint() 具备size参数 可指定outpud的元素的shape属性

    更多相关内容
  • 在python中,通过导入random库,就能使用randint 和 randrange 这两个方法来产生随机整数。那这两个方法的区别在于什么地方呢?让我们一起来看看! 区别: randint 产生的随机数区间是包含左右极限的,也就是说左右都...
  • 通过萨瑟门(Sather Gate)感受运动。
  • randint

    2021-05-25 21:46:59
    for循环用法,randint生成随机数(包括两头) import模块 from random import randint for i in range(20): print(randint(1,20))

    for循环用法,randint生成随机数(包括两头)

    import模块

    from random import randint
    for i in range(20):
        print(randint(1,20))

    展开全文
  • randint

    2021-02-24 08:02:59
    randint ******************************************************* * MOLTRAN v.2.5 * * (build number 2494) * * A program for molecular visualization, * * normal modes animation, * * and ...
  • 本文整理汇总了Python中numpy.random.randint方法的典型用法代码示例。如果您正苦于以下问题:Python random.randint方法的具体用法?Python random.randint怎么用?Python random.randint使用的例子?那么恭喜您, ...

    本文整理汇总了Python中numpy.random.randint方法的典型用法代码示例。如果您正苦于以下问题:Python random.randint方法的具体用法?Python random.randint怎么用?Python random.randint使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在模块numpy.random的用法示例。

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

    示例1: random_select

    ​点赞 6

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def random_select(img_scales):

    """Randomly select an img_scale from given candidates.

    Args:

    img_scales (list[tuple]): Images scales for selection.

    Returns:

    (tuple, int): Returns a tuple ``(img_scale, scale_dix)``,

    where ``img_scale`` is the selected image scale and

    ``scale_idx`` is the selected index in the given candidates.

    """

    assert mmcv.is_list_of(img_scales, tuple)

    scale_idx = np.random.randint(len(img_scales))

    img_scale = img_scales[scale_idx]

    return img_scale, scale_idx

    开发者ID:open-mmlab,项目名称:mmdetection,代码行数:18,

    示例2: random_sample

    ​点赞 6

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def random_sample(img_scales):

    """Randomly sample an img_scale when ``multiscale_mode=='range'``.

    Args:

    img_scales (list[tuple]): Images scale range for sampling.

    There must be two tuples in img_scales, which specify the lower

    and uper bound of image scales.

    Returns:

    (tuple, None): Returns a tuple ``(img_scale, None)``, where

    ``img_scale`` is sampled scale and None is just a placeholder

    to be consistent with :func:`random_select`.

    """

    assert mmcv.is_list_of(img_scales, tuple) and len(img_scales) == 2

    img_scale_long = [max(s) for s in img_scales]

    img_scale_short = [min(s) for s in img_scales]

    long_edge = np.random.randint(

    min(img_scale_long),

    max(img_scale_long) + 1)

    short_edge = np.random.randint(

    min(img_scale_short),

    max(img_scale_short) + 1)

    img_scale = (long_edge, short_edge)

    return img_scale, None

    开发者ID:open-mmlab,项目名称:mmdetection,代码行数:27,

    示例3: sample

    ​点赞 6

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def sample(self, batch_size):

    """

    computes (x_t,u_t,x_{t+1}) pair

    returns tuple of 3 ndarrays with shape

    (batch,x_dim), (batch, u_dim), (batch, x_dim)

    """

    if not self.initialized:

    raise ValueError("Dataset not loaded - call PlaneData.initialize() first.")

    traj=randint(0,num_t,size=batch_size) # which trajectory

    tt=randint(0,T-1,size=batch_size) # time step t for each batch

    X0=np.zeros((batch_size,x_dim))

    U0=np.zeros((batch_size,u_dim),dtype=np.int)

    X1=np.zeros((batch_size,x_dim))

    for i in range(batch_size):

    t=tt[i]

    p=self.P[traj[i], t, :]

    X0[i,:]=self.getX(traj[i],t)

    X1[i,:]=self.getX(traj[i],t+1)

    U0[i,:]=self.U[traj[i], t, :]

    return (X0,U0,X1)

    开发者ID:ericjang,项目名称:e2c,代码行数:22,

    示例4: test_count_nonzero_axis_consistent

    ​点赞 6

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def test_count_nonzero_axis_consistent(self):

    # Check that the axis behaviour for valid axes in

    # non-special cases is consistent (and therefore

    # correct) by checking it against an integer array

    # that is then casted to the generic object dtype

    from itertools import combinations, permutations

    axis = (0, 1, 2, 3)

    size = (5, 5, 5, 5)

    msg = "Mismatch for axis: %s"

    rng = np.random.RandomState(1234)

    m = rng.randint(-100, 100, size=size)

    n = m.astype(object)

    for length in range(len(axis)):

    for combo in combinations(axis, length):

    for perm in permutations(combo):

    assert_equal(

    np.count_nonzero(m, axis=perm),

    np.count_nonzero(n, axis=perm),

    err_msg=msg % (perm,))

    开发者ID:Frank-qlu,项目名称:recruit,代码行数:24,

    示例5: test_frame_negate

    ​点赞 6

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def test_frame_negate(self):

    expr = self.ex('-')

    # float

    lhs = DataFrame(randn(5, 2))

    expect = -lhs

    result = pd.eval(expr, engine=self.engine, parser=self.parser)

    assert_frame_equal(expect, result)

    # int

    lhs = DataFrame(randint(5, size=(5, 2)))

    expect = -lhs

    result = pd.eval(expr, engine=self.engine, parser=self.parser)

    assert_frame_equal(expect, result)

    # bool doesn't work with numexpr but works elsewhere

    lhs = DataFrame(rand(5, 2) > 0.5)

    if self.engine == 'numexpr':

    with pytest.raises(NotImplementedError):

    result = pd.eval(expr, engine=self.engine, parser=self.parser)

    else:

    expect = -lhs

    result = pd.eval(expr, engine=self.engine, parser=self.parser)

    assert_frame_equal(expect, result)

    开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,

    示例6: test_series_negate

    ​点赞 6

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def test_series_negate(self):

    expr = self.ex('-')

    # float

    lhs = Series(randn(5))

    expect = -lhs

    result = pd.eval(expr, engine=self.engine, parser=self.parser)

    assert_series_equal(expect, result)

    # int

    lhs = Series(randint(5, size=5))

    expect = -lhs

    result = pd.eval(expr, engine=self.engine, parser=self.parser)

    assert_series_equal(expect, result)

    # bool doesn't work with numexpr but works elsewhere

    lhs = Series(rand(5) > 0.5)

    if self.engine == 'numexpr':

    with pytest.raises(NotImplementedError):

    result = pd.eval(expr, engine=self.engine, parser=self.parser)

    else:

    expect = -lhs

    result = pd.eval(expr, engine=self.engine, parser=self.parser)

    assert_series_equal(expect, result)

    开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,

    示例7: test_series_pos

    ​点赞 6

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def test_series_pos(self):

    expr = self.ex('+')

    # float

    lhs = Series(randn(5))

    expect = lhs

    result = pd.eval(expr, engine=self.engine, parser=self.parser)

    assert_series_equal(expect, result)

    # int

    lhs = Series(randint(5, size=5))

    expect = lhs

    result = pd.eval(expr, engine=self.engine, parser=self.parser)

    assert_series_equal(expect, result)

    # bool doesn't work with numexpr but works elsewhere

    lhs = Series(rand(5) > 0.5)

    expect = lhs

    result = pd.eval(expr, engine=self.engine, parser=self.parser)

    assert_series_equal(expect, result)

    开发者ID:Frank-qlu,项目名称:recruit,代码行数:22,

    示例8: test_identity_module

    ​点赞 6

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def test_identity_module(self):

    """ identity module should preserve input """

    with IsolatedSession() as issn:

    pred_input = tf.placeholder(tf.float32, [None, None])

    final_output = tf.identity(pred_input, name='output')

    gfn = issn.asGraphFunction([pred_input], [final_output])

    for _ in range(10):

    m, n = prng.randint(10, 1000, size=2)

    mat = prng.randn(m, n).astype(np.float32)

    with IsolatedSession() as issn:

    feeds, fetches = issn.importGraphFunction(gfn)

    mat_out = issn.run(fetches[0], {feeds[0]: mat})

    self.assertTrue(np.all(mat_out == mat))

    开发者ID:databricks,项目名称:spark-deep-learning,代码行数:18,

    示例9: _sample_indices

    ​点赞 6

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def _sample_indices(self, record):

    """

    :param record: VideoRecord

    :return: list

    """

    if self.dense_sample: # i3d dense sample

    sample_pos = max(1, 1 + record.num_frames - 64)

    t_stride = 64 // self.num_segments

    start_idx = 0 if sample_pos == 1 else np.random.randint(0, sample_pos - 1)

    offsets = [(idx * t_stride + start_idx) % record.num_frames for idx in range(self.num_segments)]

    return np.array(offsets) + 1

    else: # normal sample

    average_duration = (record.num_frames - self.new_length + 1) // self.num_segments

    if average_duration > 0:

    offsets = np.multiply(list(range(self.num_segments)), average_duration) + randint(average_duration,

    size=self.num_segments)

    elif record.num_frames > self.num_segments:

    offsets = np.sort(randint(record.num_frames - self.new_length + 1, size=self.num_segments))

    else:

    offsets = np.zeros((self.num_segments,))

    return offsets + 1

    开发者ID:CMU-CREATE-Lab,项目名称:deep-smoke-machine,代码行数:24,

    示例10: resample

    ​点赞 6

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def resample(self, size=None):

    """

    Randomly sample a dataset from the estimated pdf.

    Parameters

    ----------

    size : int, optional

    The number of samples to draw. If not provided, then the size is

    the same as the underlying dataset.

    Returns

    -------

    resample : (self.d, `size`) ndarray

    The sampled dataset.

    """

    if size is None:

    size = self.n

    norm = transpose(multivariate_normal(zeros((self.d,), float),

    self.covariance, size=size))

    indices = randint(0, self.n, size=size)

    means = self.dataset[:, indices]

    return means + norm

    开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,

    示例11: _get_glyph

    ​点赞 6

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def _get_glyph(gnum, height, width, shift_prob, shift_size):

    if isinstance(gnum, list):

    n = randint(*gnum)

    else:

    n = gnum

    glyph = random_points_in_circle(

    n, 0, 0, 0.5

    )*array((width, height), 'float')

    _spatial_sort(glyph)

    if random()

    shift = ((-1)**randint(0,2))*shift_size*height

    glyph[:,1] += shift

    if random()<0.5:

    ii = randint(0,n-1,size=(1))

    xy = glyph[ii,:]

    glyph = row_stack((glyph, xy))

    return glyph

    开发者ID:inconvergent,项目名称:sand-glyphs,代码行数:23,

    示例12: rand_shape_2d

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def rand_shape_2d(dim0=10, dim1=10):

    return rnd.randint(1, dim0 + 1), rnd.randint(1, dim1 + 1)

    开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:4,

    示例13: rand_shape_3d

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def rand_shape_3d(dim0=10, dim1=10, dim2=10):

    return rnd.randint(1, dim0 + 1), rnd.randint(1, dim1 + 1), rnd.randint(1, dim2 + 1)

    开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:4,

    示例14: rand_shape_nd

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def rand_shape_nd(num_dim, dim=10):

    return tuple(rnd.randint(1, dim+1, size=num_dim))

    开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:4,

    示例15: test_sparse_nd_slice

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def test_sparse_nd_slice():

    shape = (rnd.randint(2, 10), rnd.randint(2, 10))

    stype = 'csr'

    A, _ = rand_sparse_ndarray(shape, stype)

    A2 = A.asnumpy()

    start = rnd.randint(0, shape[0] - 1)

    end = rnd.randint(start + 1, shape[0])

    assert same(A[start:end].asnumpy(), A2[start:end])

    assert same(A[start - shape[0]:end].asnumpy(), A2[start:end])

    assert same(A[start:].asnumpy(), A2[start:])

    assert same(A[:end].asnumpy(), A2[:end])

    ind = rnd.randint(-shape[0], shape[0] - 1)

    assert same(A[ind].asnumpy(), A2[ind][np.newaxis, :])

    start_col = rnd.randint(0, shape[1] - 1)

    end_col = rnd.randint(start_col + 1, shape[1])

    result = mx.nd.slice(A, begin=(start, start_col), end=(end, end_col))

    result_dense = mx.nd.slice(mx.nd.array(A2), begin=(start, start_col), end=(end, end_col))

    assert same(result_dense.asnumpy(), result.asnumpy())

    A = mx.nd.sparse.zeros('csr', shape)

    A2 = A.asnumpy()

    assert same(A[start:end].asnumpy(), A2[start:end])

    result = mx.nd.slice(A, begin=(start, start_col), end=(end, end_col))

    result_dense = mx.nd.slice(mx.nd.array(A2), begin=(start, start_col), end=(end, end_col))

    assert same(result_dense.asnumpy(), result.asnumpy())

    def check_slice_nd_csr_fallback(shape):

    stype = 'csr'

    A, _ = rand_sparse_ndarray(shape, stype)

    A2 = A.asnumpy()

    start = rnd.randint(0, shape[0] - 1)

    end = rnd.randint(start + 1, shape[0])

    # non-trivial step should fallback to dense slice op

    result = mx.nd.sparse.slice(A, begin=(start,), end=(end + 1,), step=(2,))

    result_dense = mx.nd.slice(mx.nd.array(A2), begin=(start,), end=(end + 1,), step=(2,))

    assert same(result_dense.asnumpy(), result.asnumpy())

    shape = (rnd.randint(2, 10), rnd.randint(1, 10))

    check_slice_nd_csr_fallback(shape)

    开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:43,

    示例16: test_sparse_nd_concat

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def test_sparse_nd_concat():

    def check_concat(arrays):

    ret = np.concatenate([arr.asnumpy() for arr in arrays], axis=0)

    same(mx.nd.concat(*arrays, dim=0).asnumpy(), ret)

    nds = []

    zero_nds = []

    ncols = rnd.randint(2, 10)

    for i in range(3):

    shape = (rnd.randint(2, 10), ncols)

    A, _ = rand_sparse_ndarray(shape, 'csr')

    nds.append(A)

    zero_nds.append(mx.nd.zeros(shape).tostype('csr'))

    check_concat(nds)

    check_concat(zero_nds)

    开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:16,

    示例17: test_sparse_nd_binary_scalar_op

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def test_sparse_nd_binary_scalar_op():

    N = 3

    def check(fn, stype, out_stype=None):

    for _ in range(N):

    ndim = 2

    shape = np.random.randint(1, 6, size=(ndim,))

    npy = np.random.normal(0, 1, size=shape)

    nd = mx.nd.array(npy).tostype(stype)

    if out_stype is not None:

    assert(nd.stype == out_stype)

    assert_allclose(fn(npy), fn(nd).asnumpy(), rtol=1e-4, atol=1e-4)

    stypes = ['row_sparse', 'csr']

    for stype in stypes:

    check(lambda x: 1 + x, stype)

    check(lambda x: 1 - x, stype)

    check(lambda x: 1 * x, stype)

    check(lambda x: 1 / x, stype)

    check(lambda x: 2 ** x, stype)

    check(lambda x: 1 > x, stype)

    check(lambda x: 0.5 > x, stype)

    check(lambda x: 0.5 < x, stype)

    check(lambda x: 0.5 >= x, stype)

    check(lambda x: 0.5 <= x, stype)

    check(lambda x: 0.5 == x, stype)

    check(lambda x: x / 2, stype, out_stype=stype)

    check(lambda x: x + 0, stype, out_stype=stype)

    check(lambda x: x - 0, stype, out_stype=stype)

    开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:30,

    示例18: test_sparse_nd_binary_iop

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def test_sparse_nd_binary_iop():

    N = 3

    def check_binary(fn, stype):

    for _ in range(N):

    ndim = 2

    oshape = np.random.randint(1, 6, size=(ndim,))

    lshape = list(oshape)

    rshape = list(oshape)

    lhs = np.random.uniform(0, 1, size=lshape)

    rhs = np.random.uniform(0, 1, size=rshape)

    lhs_nd = mx.nd.array(lhs).tostype(stype)

    rhs_nd = mx.nd.array(rhs).tostype(stype)

    assert_allclose(fn(lhs, rhs),

    fn(lhs_nd, rhs_nd).asnumpy(),

    rtol=1e-4, atol=1e-4)

    def inplace_add(x, y):

    x += y

    return x

    def inplace_mul(x, y):

    x *= y

    return x

    stypes = ['csr', 'row_sparse']

    fns = [inplace_add, inplace_mul]

    for stype in stypes:

    for fn in fns:

    check_binary(fn, stype)

    开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:29,

    示例19: test_sparse_nd_save_load

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def test_sparse_nd_save_load():

    repeat = 1

    stypes = ['default', 'row_sparse', 'csr']

    stype_dict = {'default': NDArray, 'row_sparse': RowSparseNDArray, 'csr': CSRNDArray}

    num_data = 20

    densities = [0, 0.5]

    fname = 'tmp_list.bin'

    for _ in range(repeat):

    data_list1 = []

    for i in range(num_data):

    stype = stypes[np.random.randint(0, len(stypes))]

    shape = rand_shape_2d(dim0=40, dim1=40)

    density = densities[np.random.randint(0, len(densities))]

    data_list1.append(rand_ndarray(shape, stype, density))

    assert isinstance(data_list1[-1], stype_dict[stype])

    mx.nd.save(fname, data_list1)

    data_list2 = mx.nd.load(fname)

    assert len(data_list1) == len(data_list2)

    for x, y in zip(data_list1, data_list2):

    assert same(x.asnumpy(), y.asnumpy())

    data_map1 = {'ndarray xx %s' % i: x for i, x in enumerate(data_list1)}

    mx.nd.save(fname, data_map1)

    data_map2 = mx.nd.load(fname)

    assert len(data_map1) == len(data_map2)

    for k, x in data_map1.items():

    y = data_map2[k]

    assert same(x.asnumpy(), y.asnumpy())

    os.remove(fname)

    开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:32,

    示例20: get_minibatch

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def get_minibatch(roidb, num_classes):

    """Given a roidb, construct a minibatch sampled from it."""

    num_images = len(roidb)

    # Sample random scales to use for each image in this batch

    random_scale_inds = npr.randint(0, high=len(cfg.TRAIN.SCALES),

    size=num_images)

    assert(cfg.TRAIN.BATCH_SIZE % num_images == 0), \

    'num_images ({}) must divide BATCH_SIZE ({})'. \

    format(num_images, cfg.TRAIN.BATCH_SIZE)

    # Get the input image blob, formatted for caffe

    im_blob, im_scales = _get_image_blob(roidb, random_scale_inds)

    blobs = {'data': im_blob}

    assert len(im_scales) == 1, "Single batch only"

    assert len(roidb) == 1, "Single batch only"

    # gt boxes: (x1, y1, x2, y2, cls)

    if cfg.TRAIN.USE_ALL_GT:

    # Include all ground truth boxes

    gt_inds = np.where(roidb[0]['gt_classes'] != 0)[0]

    else:

    # For the COCO ground truth boxes, exclude the ones that are ''iscrowd''

    gt_inds = np.where(roidb[0]['gt_classes'] != 0 & np.all(roidb[0]['gt_overlaps'].toarray() > -1.0, axis=1))[0]

    gt_boxes = np.empty((len(gt_inds), 5), dtype=np.float32)

    gt_boxes[:, 0:4] = roidb[0]['boxes'][gt_inds, :] * im_scales[0]

    gt_boxes[:, 4] = roidb[0]['gt_classes'][gt_inds]

    blobs['gt_boxes'] = gt_boxes

    blobs['im_info'] = np.array(

    [[im_blob.shape[1], im_blob.shape[2], im_scales[0]]],

    dtype=np.float32)

    blobs['img_id'] = roidb[0]['img_id']

    return blobs

    开发者ID:guoruoqian,项目名称:cascade-rcnn_Pytorch,代码行数:38,

    示例21: _sample_indices

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def _sample_indices(self, record):

    """

    :param record: VideoRecord

    :return: list

    """

    average_duration = (record.num_frames - self.new_length + 1) // self.num_segments

    if average_duration > 0:

    offsets = np.multiply(list(range(self.num_segments)), average_duration) + randint(average_duration, size=self.num_segments)

    elif record.num_frames > self.num_segments:

    offsets = np.sort(randint(record.num_frames - self.new_length + 1, size=self.num_segments))

    else:

    offsets = np.zeros((self.num_segments,))

    return offsets + 1

    开发者ID:yjxiong,项目名称:tsn-pytorch,代码行数:17,

    示例22: __call__

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def __call__(self, image, boxes=None, labels=None):

    if random.randint(2):

    image[:, :, 1] *= random.uniform(self.lower, self.upper)

    return image, boxes, labels

    开发者ID:soo89,项目名称:CSD-SSD,代码行数:7,

    示例23: compute_traj

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def compute_traj(self, max_dist=1):

    # computes P,U data for single trajectory

    # all P,U share the same environment obstacles.png

    P=np.zeros((T,2),dtype=np.int) # r,c position

    U=np.zeros((T,u_dim),dtype=np.int)

    P[0,:]=[rw,randint(rw,w-rw)] # initial location

    for t in range(1,T):

    p=np.copy(P[t-1,:])

    # dr direction

    d=randint(-1,2) # direction

    nsteps=randint(max_dist+1)

    dr=d*nsteps # applied control

    for i in range(nsteps):

    p[0]+=d

    if self.is_colliding(p):

    p[0]-=d

    break

    # dc direction

    d=randint(-1,2) # direction

    nsteps=randint(max_dist+1)

    dc=d*nsteps # applied control

    for i in range(nsteps):

    p[1]+=d

    if self.is_colliding(p):

    p[1]-=d # step back

    break

    P[t,:]=p

    U[t,:]=[dr,dc]

    return P,U

    开发者ID:ericjang,项目名称:e2c,代码行数:31,

    示例24: __call__

    ​点赞 5

    # 需要导入模块: from numpy import random [as 别名]

    # 或者: from numpy.random import randint [as 别名]

    def __call__(self, img, boxes, labels):

    if random.randint(2):

    return img, boxes, labels

    h, w, c = img.shape

    ratio = random.uniform(self.min_ratio, self.max_ratio)

    expand_img = np.full((int(h * ratio), int(w * ratio), c),

    self.mean).astype(img.dtype)

    left = int(random.uniform(0, w * ratio - w))

    top = int(random.uniform(0, h * ratio - h))

    expand_img[top:top + h, left:left + w] = img

    img = expand_img

    boxes += np.tile((left, top), 2)

    return img, boxes, labels

    开发者ID:dingjiansw101,项目名称:AerialDetection,代码行数:16,

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

    展开全文
  • np.random.randint和random.randint的区别

    千次阅读 2022-02-24 10:00:49
    a = np.random.randint(0, 2) b = random.randint(0, 2) lista.append(a) listb.append(b) print(lista) print(listb) 运行结果: [0, 0, 0, 0, 1, 0, 0, 1, 0, 1] [0, 1, 0, 1, 2, 0, 2, 1, 0, 0] 可以
    import random
    import numpy as np
    
    lista = []
    listb = []
    for _ in range(10):
        a = np.random.randint(0, 2)
        b = random.randint(0, 2)
        lista.append(a)
        listb.append(b)
    print(lista)
    print(listb)
    运行结果:
    [0, 0, 0, 0, 1, 0, 0, 1, 0, 1]
    [0, 1, 0, 1, 2, 0, 2, 1, 0, 0]
    

    可以看出:
    np.random.randint 不包含上限
    random.randint包含上限

    使用情况举例

      if random.randint(0, 1):
          pass
       else:
          pass
      作为条件判断代码显得简洁          
    
    展开全文
  • Matlab的randint函数用法

    2021-04-18 16:28:44
    RANDINT Generate matrix of uniformly distributed random integers.OUT = RANDINT generates a "0" or "1" with equal probability.OUT = RANDINT(M) generates an M-by-M matrix of random binary numbers."0" an...
  • Python randint()用法及代碼示例

    千次阅读 2020-12-19 02:30:52
    randint()是Python3中隨機模塊的內置函數。隨機模塊提供對各種有用功能的訪問,其中一個功能可以生成隨機數,即randint()。句法:randint(start, end)參數:(start, end): Both of them must be integer type values...
  • Python randint()用法及代码示例

    千次阅读 2020-11-21 02:23:54
    randint()是Python3中随机模块的内置函数。随机模块提供对各种有用功能的访问,其中一个功能可以生成随机数,即randint()。句法:randint(start, end)参数:(start, end): Both of them must be integer type values...
  • torch.randint()

    千次阅读 2022-03-09 09:08:28
    torch.randint()
  • random.randint函数用法

    千次阅读 2022-07-17 17:40:46
    random.randint()用法记录
  • MATLAB只randint函数

    2021-12-11 15:49:00
    s=randint(M,N,range); 生成MxN的矩阵,矩阵中元素的取值为小于range的整数。 M=4; N=3; range=3; s=randint(M,N,range) 注意: randi函数生成元素取值为1:M的N*range的矩阵。
  • np.random.randint函数

    2022-04-11 16:45:55
    numpy.random.randint(low, high=None, size=None, dtype=‘l’) 函数的作用是,返回一个随机整型数,范围从低(包括)到高(不包括),即[low, high)。 如果没有写参数high的值,则返回[0,low)的值。 参数如下: ...
  • 原博文2016-06-28 23:29 −引入模块的方法: from 模块名 import 方法名 范例: from random import randint#使用randint需要加上这句 while True: answer=randint(1,100) if answer>70: print(answer) ......
  • >> x = randn(1,10) x = Columns 1 through 6 -0.1623 -0.1461 -0.5320 1.6821 -0.8757 -0.4838 Columns 7 through 10 -0.7120 -1.1742 -0.1922 -0.2741 (3)function3:randint matlab 中 randint 是产生整数随机数...
  • 作为一个实例rv_discrete类,randint对象从中继承了通用方法的集合(完整列表请参见下文),并使用特定于此特定发行版的详细信息来完善它们。注意:的概率质量函数randint是:对于k = low, ..., high - 1。randint需要...
  • Python:randint()用法

    千次阅读 2020-11-21 02:23:54
    原博文2020-05-24 17:20 −randint(a, b)随机生成整数:[a-b]区间的整数(包含两端)1 from random import randint2 print("随机生成10个随机整数。")3 i = 04 while True:5 i += 16 print(randint(0,10))...09959...
  • “随机”取整(“random” randint)天有不测风云,人有祸福旦夕。买彩票的人说不定哪天会中奖,或者天上掉下金砖砸中你也说不定。貌似我们上天自有安排,很多事情我们无法决定,正所谓塞翁失马,焉知祸福。在现在所谓...
  • MATLAB中randint与randi的区别

    千次阅读 2021-03-25 16:49:50
    randint在后期版本中会被randi代替,并且两者格式不同。 例如:M = randint(A,B,[C D]) 但在randi中的表示为:M = randi([C D],A,B) randint的功能:randint在MATLAB中用于产生基质的均匀分布的随机整数。 用法:M =...
  • Python中的randint()方法

    万次阅读 多人点赞 2020-07-18 06:14:52
    In this tutorial, we are going to focus on the randint() method in Python. In our previous tutorials, we saw different random number generating methods defined inside the random mod...
  • 为了添加@RoryDaulton的出色答案,我运行了randint(1:110),生成一个频率计数,并将其转换为计数的R向量,如下所示:hits = {i:0 for i in range(1,111)}for i in range(1000000): hits[randint(1,110)] += 1hits = ...
  • np.random.randint() 根据参数中所指定的范围生成随机 `整数`。
  • 使用random函数实现randint函数的功能

    千次阅读 2020-11-28 11:17:48
    1)内的随机小数print(random.random())#生成某一范围(0-1)内的随机小数print(random.random())randint也是random中的一个#生成指定范围内的随机整数print(random.randint(1...
  • matlab中rand函数是产生0到1的随机分布matlab中randn函数是产生标准正态分布randint是产生整数随机数,默认为0和1%%%%%%%%%%%rand%%%%%%%%%%%%%%%%RANDUniformly distributedrandomnumbers.标准化分布的随机数RAND(N...
  • in random = random.randint(1, 10) AttributeError: 'int' object has no attribute 'randint' I've tried changing the title so that it doesn't include the word random and it still doesn't work, I've ...
  • np.random.randint()

    2021-03-29 14:54:44
    np.random.randint()
  • random.randint()用法

    千次阅读 2022-02-14 16:01:09
    random.randint(参数1,参数2) 参数1、参数2必须是整数 函数返回参数1和参数2之间的任意整数, 闭区间 举例: import random result = random.randint(1,10) #返回 [1, 10] 之间的任意整数 print("result: ",result)...
  • randint是random + integer拼接简写而成,代表随机一个整数Python标准库中的random函数,可以生成随机浮点数、整数、字符串,甚至帮助你随机选择列表序列中的一个元素,打乱一组数据等。random.randint() 函数的例子...

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 152,683
精华内容 61,073
关键字:

randint