You are close, you want to use np.tile, but like this:

a = np.array([0,1,2])
np.tile(a,(3,1))

Result:

array([[0, 1, 2],
   [0, 1, 2],
   [0, 1, 2]])

If you call np.tile(a,3) you will get concatenate behavior like you were seeing

array([0, 1, 2, 0, 1, 2, 0, 1, 2])

http://docs.scipy.org/doc/numpy/reference/generated/numpy.tile.html

Answer from Cory Kramer on Stack Overflow
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.stack.html
numpy.stack — NumPy v2.5 Manual
In the case of a single ndarray array_like input, it will be treated as a sequence of arrays; i.e., each element along the zeroth axis is treated as a separate array. ... The axis in the result array along which the input arrays are stacked.
🌐
IncludeHelp
includehelp.com › python › concatenate-or-clone-a-numpy-array-n-times.aspx
Python - Concatenate (or clone) a NumPy array N times
October 10, 2023 - Suppose we need to work on a MxN NumPy matrix by cloning an Mx1 ndarray N times, we need to find an appropriate approach for this. For this purpose, we first need to define a value of N, and then we will create a NumPy array. Now we will use numpy.vstack() method. This method stacks arrays ...
🌐
IncludeHelp
includehelp.com › python › numpy-stack-an-array-vertically-and-tile-array-n-times.aspx
Python NumPy - Stack an Array Vertically and Tile Array n Times
September 11, 2024 - We will then use numpy.row_stack() to stack the tiled array vertically, and stores the result in another variable. ... # Importing numpy import numpy as np # Creating an array arr = np.array([1, 2, 3, 4]) # Display original array print("Original array", arr,"\n") # Defining a value for n n ...
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.vstack.html
numpy.vstack — NumPy v2.5 Manual
Stack 1-D arrays as columns into a 2-D array. ... Split an array into multiple sub-arrays vertically (row-wise). ... Split an array into a tuple of sub-arrays along an axis. ... Try it in your browser! >>> import numpy as np >>> a = np.array([1, 2, 3]) >>> b = np.array([4, 5, 6]) >>> np.vstack((a,b)) array([[1, 2, 3], [4, 5, 6]])
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.stack.html
numpy.stack — NumPy v2.6.dev0 Manual
In the case of a single ndarray array_like input, it will be treated as a sequence of arrays; i.e., each element along the zeroth axis is treated as a separate array. ... The axis in the result array along which the input arrays are stacked.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-stack-in-python
numpy.stack() in Python - GeeksforGeeks
December 13, 2025 - Explanation: np.stack((a, b), axis=0) creates a new 0th axis and places arrays one below another. ... Example 1: This example shows how stacking the same 1D arrays along axis 0, 1, and -1 changes the output shape. ... import numpy as np a = np.array([1, 2, 3]) b = np.array([4, 5, 6]) print(np.stack((a, b), axis=0)) print(np.stack((a, b), axis=1)) print(np.stack((a, b), axis=-1))
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.dstack.html
numpy.dstack — NumPy v2.5 Manual
Stack 1-D arrays as columns into a 2-D array. ... Split array along third axis. ... Try it in your browser! >>> import numpy as np >>> a = np.array((1,2,3)) >>> b = np.array((4,5,6)) >>> np.dstack((a,b)) array([[[1, 4], [2, 5], [3, 6]]])
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.stack.html
numpy.stack — NumPy v2.3 Manual
In the case of a single ndarray array_like input, it will be treated as a sequence of arrays; i.e., each element along the zeroth axis is treated as a separate array. ... The axis in the result array along which the input arrays are stacked.
Find elsewhere
Top answer
1 of 3
20

One can use np.repeat methods together with np.newaxis:

import numpy as np

test = np.random.randn(40,40,3)
result = np.repeat(test[np.newaxis,...], 10, axis=0)
print(result.shape)
>> (10, 40, 40, 3)
2 of 3
10

Assuming you're looking to copy the values 10 times, you can just stack 10 of the array:

def repeat(arr, count):
    return np.stack([arr for _ in range(count)], axis=0)

axis=0 is actually the default, so it's not really necessary here, but I think it makes it clearer that you're adding the new axis on the front.


In fact, this is pretty much identical to what the examples for stack are doing:

>>> arrays = [np.random.randn(3, 4) for _ in range(10)]
>>> np.stack(arrays, axis=0).shape
(10, 3, 4)

At first glance you might think repeat or tile would be a better fit.

But repeat is about repeating over an existing axis (or flattening the array), so you'd need to reshape either before or after. (Which is just as efficient, but I think not as simple.)

And tile (assuming you use an array-like reps—with scalar reps it basically repeat) is about filling out a multidimensional spec in all directions, which is much more complex than what you want for this simple case.


All of these options will be equally efficient. They all copy the data 10 times over, which is the expensive part; the cost of any internal processing, building tiny intermediate objects, etc. is irrelevant. The only way to make it faster is to avoid copying. Which you probably don't want to do.

But if you do… To share row storage across the 10 copies, you probably want broadcast_to:

def repeat(arr, count):
    return np.broadcast_to(arr, (count,)+arr.shape)

Notice that broadcast_to doesn't actually guarantee that it avoids copying, just that it returns some kind of readonly view where "more than one element of a broadcasted array may refer to a single memory location". In practice, it's going to avoid copying. If you actually need that to be guaranteed for some reason (or if you want a writable view—which is usually going to be a terrible idea, but maybe you have a good reason…), you have to drop down to as_strided:

def repeat(arr, count):
    shape = (count,) + arr.shape
    strides = (0,) + arr.strides
    return np.lib.stride_tricks.as_strided(
        arr, shape=shape, strides=strides, writeable=False)

Notice that half the docs for as_strided are warning that you probably shouldn't use it, and the other half are warning that you definitely shouldn't use it for writable views, so… make sure this is what you want before doing it.

🌐
Python Guides
pythonguides.com › python-numpy-repeat
NumPy repeat(): Elements, Rows, Columns and vs tile
September 27, 2026 - import numpy as np row = np.array([1, 2, 3]) # repeat a ROW n times: stack copies of it print("row repeated 3 times:") print(np.tile(row, (3, 1))) print() # a column, widened col = np.array([[1], [2], [3]]) print("column repeated 4 times:") ...
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.repeat.html
numpy.repeat — NumPy v2.5 Manual
Find the unique elements of an array. ... Try it in your browser! >>> import numpy as np >>> np.repeat(3, 4) array([3, 3, 3, 3]) >>> x = np.array([[1,2],[3,4]]) >>> np.repeat(x, 2) array([1, 1, 2, 2, 3, 3, 4, 4]) >>> np.repeat(x, 3, axis=1) array([[1, 1, 1, 2, 2, 2], [3, 3, 3, 4, 4, 4]]) >>> np.repeat(x, [1, 2], axis=0) array([[1, 2], [3, 4], [3, 4]])
Top answer
1 of 3
7

There are a number of options in numpy:

  1. The simplest is np.stack, with the new axis set to 0:

    result = np.stack((arr,) * m, axis=0)
    

    This is a generalization of np.vstack, which can accept a variable m in the same way:

    result = np.vstack((arr,) * m)
    
  2. Since you are looking to expand the first dimension and not the second, you can use np.tile:

    result = np.tile(arr, [m, 1])
    
  3. For this simple case, you can repeat the elements individually for the same result using np.repeat. This is a bit hacky, but it works just as well:

    result = np.repeat([arr], m, axis=0)
    

    If arr is already a numpy array, you can add the leading dimension more explicitly:

    result = np.repeat(arr[None, :], m, axis=0)
    
  4. A slightly more convoluted method, but which showcases what is going on under the hood better is using np.concatenate:

    np.concatenate(([arr],) * m, axis=0)
    
  5. In the same spirit as concatenate, you can use the constructor np.array directly:

    np.array([arr] * m)
    
  6. An ugly method is to use muliplication (combined with broadcasting):

    result = arr * np.ones((m, 1), dtype=np.int8)
    

    Setting the dtype to a very small integer type pretty much ensures that the result will be promoted to the actual type of your array.

  7. The previous methods copy the array multiple times to get the 2D data. But since the data is repeated, you don't actually need to copy it. Instead, you can make a view that creates a fake first dimension using broadcasting. Specifically, the np.broadcast_to function will do exactly what you want:

     result = np.broadcast_to(arr, [m, len(arr)])
    
  8. There is a more general approach even than the previous to making views is np.lib.stride_tricks.as_strided.

    First, let's reiterate the warning from the documentation:

    Warning

    This function has to be used with extreme care, see notes.

    Unless you know the byte-size of the dtype you plan on using ahead of time, it's a good idea to ensure that arr is a numpy array to get the strides from it:

    arr = np.asanyarray(arr)
    result = np.lib.stride_tricks.as_strided(arr, shape=(m, arr.size), strides=(0,) + arr.strides)
    

In the last two cases, if you want to expand the view into a full buffer that contains a proper copy for each element, you can copy the data:

result = result.copy()

If you don't do the expansion, you will effectively be simulating the behavior of multiple references to the same list, where modifying any element changes all elements in the same column.

2 of 3
1

You can use:

import numpy as np
arr, m = [1,2,3,4], 3

np.vstack([arr]*m)

Output:

array([[1, 2, 3, 4],
       [1, 2, 3, 4],
       [1, 2, 3, 4]])

On another note, why do you need to create such a matrix? You may be looking for numpy broadcasting without the need of repeating your array.

🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.vstack.html
numpy.vstack — NumPy v2.1 Manual
Stack 1-D arrays as columns into a 2-D array. ... Split an array into multiple sub-arrays vertically (row-wise). ... Split an array into a tuple of sub-arrays along an axis. ... >>> import numpy as np >>> a = np.array([1, 2, 3]) >>> b = np.array([4, 5, 6]) >>> np.vstack((a,b)) array([[1, 2, 3], [4, 5, 6]])
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.stack.html
numpy.stack — NumPy v2.0 Manual
>>> arrays = [np.random.randn(3, 4) for _ in range(10)] >>> np.stack(arrays, axis=0).shape (10, 3, 4)
🌐
w3resource
w3resource.com › numpy › manipulation › vstack.php
NumPy: numpy.vstack() function - w3resource
April 24, 2026 - Use numpy.vstack() when you need to combine two or more arrays with the same number of columns into a single array by stacking them vertically.
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_stacking_arrays.htm
NumPy - Stacking Arrays
We can use the stack() function in NumPy to stack a sequence of arrays along a new axis, creating a new dimension in the result.
🌐
Towards Data Science
towardsdatascience.com › home › data science › np.stack() - how to stack two arrays in numpy and python
np.stack() - How To Stack two Arrays in Numpy And Python | Towards Data Science
January 10, 2023 - Numpy's np stack function is used to stack/join arrays along a new axis. It will return a single array as a result of stacking multiple sequences with the same shape.
🌐
NumPy
numpy.org › doc › 1.18 › reference › generated › numpy.stack.html
numpy.stack — NumPy v1.18 Manual
May 24, 2020 - >>> arrays = [np.random.randn(3, 4) for _ in range(10)] >>> np.stack(arrays, axis=0).shape (10, 3, 4)