7 examples of 'python repeat n times' in Python

Every line of 'python repeat n times' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
13def repeat(object, times = 0):
14 yield object
37@public
38def repeat(obj, nrepeat=None):
39 """Generator to repeatedly yield the same object
40
41 Args:
42 obj (any): The object to yield
43
44 Kwargs:
45 nrepeat (int): The number of times to repeatedly yield obj
46 """
47 if nrepeat is None:
48 return itertools.repeat(obj)
49 else:
50 return itertools.repeat(obj, times=nrepeat)
93def fillRepeat(container, func, n):
94 return container(func() for _ in xrange(n))
382def repeat(a, repeats, axis=None):
383 """
384 Repeat elements of an array.
385
386 Parameters
387 ----------
388 a : array_like
389 Input array.
390 repeats : int or array of ints
391 The number of repetitions for each element. `repeats` is broadcasted
392 to fit the shape of the given axis.
393 axis : int, optional
394 The axis along which to repeat values. By default, use the
395 flattened input array, and return a flat output array.
396
397 Returns
398 -------
399 repeated_array : ndarray
400 Output array which has the same shape as `a`, except along
401 the given axis.
402
403 See Also
404 --------
405 tile : Tile an array.
406
407 Examples
408 --------
409 >>> np.repeat(3, 4)
410 array([3, 3, 3, 3])
411 >>> x = np.array([[1,2],[3,4]])
412 >>> np.repeat(x, 2)
413 array([1, 1, 2, 2, 3, 3, 4, 4])
414 >>> np.repeat(x, 3, axis=1)
415 array([[1, 1, 1, 2, 2, 2],
416 [3, 3, 3, 4, 4, 4]])
417 >>> np.repeat(x, [1, 2], axis=0)
418 array([[1, 2],
419 [3, 4],
420 [3, 4]])
421
422 """
423 return _wrapfunc(a, 'repeat', repeats, axis=axis)
354def repeat(a, repeats, axis=None):
355 """
356 Repeat elements of an array.
357
358 Parameters
359 ----------
360 a : array_like
361 Input array.
362 repeats : int or array of ints
363 The number of repetitions for each element. `repeats` is broadcasted
364 to fit the shape of the given axis.
365 axis : int, optional
366 The axis along which to repeat values. By default, use the
367 flattened input array, and return a flat output array.
368
369 Returns
370 -------
371 repeated_array : ndarray
372 Output array which has the same shape as `a`, except along
373 the given axis.
374
375 See Also
376 --------
377 tile : Tile an array.
378
379 Examples
380 --------
381 >>> x = np.array([[1,2],[3,4]])
382 >>> np.repeat(x, 2)
383 array([1, 1, 2, 2, 3, 3, 4, 4])
384 >>> np.repeat(x, 3, axis=1)
385 array([[1, 1, 1, 2, 2, 2],
386 [3, 3, 3, 4, 4, 4]])
387 >>> np.repeat(x, [1, 2], axis=0)
388 array([[1, 2],
389 [3, 4],
390 [3, 4]])
391
392 """
393 try:
394 repeat = a.repeat
395 except AttributeError:
396 return _wrapit(a, 'repeat', repeats, axis)
397 return repeat(repeats, axis)
662def __repeat__(self):
663 for _ in pyv.xrange(5):
664 yield
52def repeat(xs, length):
53 return xs * int(length / len(xs)) + xs[:length % len(xs)]

Related snippets