# 3 examples of 'numpy repeat' in Python

Every line of 'numpy repeat' 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
``354def repeat(a, repeats, axis=None):355    """356    Repeat elements of an array.357358    Parameters359    ----------360    a : array_like361        Input array.362    repeats : int or array of ints363        The number of repetitions for each element.  `repeats` is broadcasted364        to fit the shape of the given axis.365    axis : int, optional366        The axis along which to repeat values.  By default, use the367        flattened input array, and return a flat output array.368369    Returns370    -------371    repeated_array : ndarray372        Output array which has the same shape as `a`, except along373        the given axis.374375    See Also376    --------377    tile : Tile an array.378379    Examples380    --------381    &gt;&gt;&gt; x = np.array([[1,2],[3,4]])382    &gt;&gt;&gt; np.repeat(x, 2)383    array([1, 1, 2, 2, 3, 3, 4, 4])384    &gt;&gt;&gt; np.repeat(x, 3, axis=1)385    array([[1, 1, 1, 2, 2, 2],386           [3, 3, 3, 4, 4, 4]])387    &gt;&gt;&gt; np.repeat(x, [1, 2], axis=0)388    array([[1, 2],389           [3, 4],390           [3, 4]])391392    """393    try:394        repeat = a.repeat395    except AttributeError:396        return _wrapit(a, 'repeat', repeats, axis)397    return repeat(repeats, axis)``
``382def repeat(a, repeats, axis=None):383    """384    Repeat elements of an array.385386    Parameters387    ----------388    a : array_like389        Input array.390    repeats : int or array of ints391        The number of repetitions for each element.  `repeats` is broadcasted392        to fit the shape of the given axis.393    axis : int, optional394        The axis along which to repeat values.  By default, use the395        flattened input array, and return a flat output array.396397    Returns398    -------399    repeated_array : ndarray400        Output array which has the same shape as `a`, except along401        the given axis.402403    See Also404    --------405    tile : Tile an array.406407    Examples408    --------409    &gt;&gt;&gt; np.repeat(3, 4)410    array([3, 3, 3, 3])411    &gt;&gt;&gt; x = np.array([[1,2],[3,4]])412    &gt;&gt;&gt; np.repeat(x, 2)413    array([1, 1, 2, 2, 3, 3, 4, 4])414    &gt;&gt;&gt; np.repeat(x, 3, axis=1)415    array([[1, 1, 1, 2, 2, 2],416           [3, 3, 3, 4, 4, 4]])417    &gt;&gt;&gt; np.repeat(x, [1, 2], axis=0)418    array([[1, 2],419           [3, 4],420           [3, 4]])421422    """423    return _wrapfunc(a, 'repeat', repeats, axis=axis)``
``145def repeat(input, repeats, dim):146    return np.repeat(input, repeats, axis=dim)``