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.

Answer from Mad Physicist on Stack Overflow
🌐
NumPy
numpy.org › doc › 2.5 › reference › generated › numpy.repeat.html
numpy.repeat — NumPy v2.5 Manual
The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
🌐
NumPy
numpy.org › doc › 2.3 › reference › generated › numpy.repeat.html
numpy.repeat — NumPy v2.3 Manual
The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.repeat.html
numpy.repeat — NumPy v2.6.dev0 Manual
The number of repetitions for each element. repeats is broadcasted to fit the shape of the given axis.
🌐
w3resource
w3resource.com › numpy › manipulation › repeat.php
NumPy: numpy.repeat() function - w3resource
April 24, 2026 - The numpy.repeat() function is primarily used to repeat elements of an array, creating a new array with repeated values based on the specified repetition count.
🌐
Programiz
programiz.com › python-programming › numpy › methods › repeat
NumPy repeat() | Programiz
August 30, 2023 - The repeat() method repeats the elements of the input arrays a given number of times. import numpy as np numbers = np.array([0, 1, 2, 3])
🌐
Codecademy
codecademy.com › docs › python:numpy › built-in functions › .repeat()
Python:NumPy | Built-in Functions | .repeat() | Codecademy
April 8, 2025 - The .repeat() function in NumPy is used to duplicate items in an array. It provides the option to specify the number of times each element appears, and whether that repetition happens across a specific axis or not.
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.

Find elsewhere
🌐
Codecademy
codecademy.com › docs › python:numpy › ndarray › .repeat()
Python:NumPy | ndarray | .repeat() | Codecademy
November 4, 2025 - The .repeat() method of a NumPy ndarray returns a new array where each element is repeated a specified number of times.
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-repeat-python
numpy.repeat() in Python - GeeksforGeeks
March 28, 2022 - The numpy.repeat() function repeats elements of the array - arr.
🌐
NumPy
numpy.org › doc › 1.17 › reference › generated › numpy.repeat.html
numpy.repeat — NumPy v1.17 Manual
February 18, 2020 - >>> 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]])
🌐
Medium
giulio-laurenti.medium.com › repeating-the-elements-of-numpy-arrays-9da737f578c9
Repeating the Elements of Numpy Arrays | by Giulio Laurenti, PhD | Medium
June 30, 2025 - We can repeat each element a specific number of times by passing an array of integers instead of an integer.
🌐
TutorialsPoint
tutorialspoint.com › numpy › numpy_repeat_function.htm
Numpy repeat() Function
This function either repeats elements by their number of repetitions or a single value for the repetitions of all elements. The numpy.repeat() function repeats the elements of an array along a specified axis. If the axis is not provided, the ...
🌐
Python Guides
pythonguides.com › python-numpy-repeat
NumPy repeat(): Elements, Rows, Columns and vs tile
September 27, 2026 - The result is always a new array. np.repeat never modifies the input. This is the surprise. Leave axis out on a 2D array and you get a flat 1D result: import numpy as np m = np.array([[1, 2], [3, 4]]) print("original:") print(m) print("\nno axis (the DEFAULT) flattens first:") print(np.repeat(m, 2), " shape", np.repeat(m, 2).shape) print("\naxis=0 repeats rows:") print(np.repeat(m, 2, axis=0)) print("\naxis=1 repeats columns:") print(np.repeat(m, 2, axis=1))
🌐
Vultr Docs
docs.vultr.com › python › third party › numpy › repeat()
Python Numpy repeat() - Repeat Elements | Vultr Docs
November 14, 2024 - The numpy.repeat() function in ... the NumPy library. This function repeats elements of an array a specified number of times, creating a larger array according to the defined pattern....