Using np.repeat and np.tile on x and y respectively to get the desired columns and then stacking them together with z into one array:

Use with AIimport numpy as np

x = [1, 2, 3]
y = [4, 5]
z = [6, 7, 8, 9, 10, 11]

a = np.array([np.repeat(x, 2), np.tile(y, 3), z]).T

result:

Use with AIarray([[ 1,  4,  6],
       [ 1,  5,  7],
       [ 2,  4,  8],
       [ 2,  5,  9],
       [ 3,  4, 10],
       [ 3,  5, 11]])
Answer from kuzand on Stack Overflow
🌐
NumPy
numpy.org › doc › 2.1 › reference › generated › numpy.ndarray.fill.html
numpy.ndarray.fill — NumPy v2.1 Manual
>>> import numpy as np >>> a = np.array([1, 2]) >>> a.fill(0) >>> a array([0, 0]) >>> a = np.empty(2) >>> a.fill(1) >>> a array([1., 1.])
🌐
GeeksforGeeks
geeksforgeeks.org › python › numpy-ndarray-fill-in-python
numpy.ndarray.fill() in Python - GeeksforGeeks
December 28, 2018 - DSA Python · Data Science · NumPy · Pandas · Practice · Django · Flask · Last Updated : 28 Dec, 2018 · numpy.ndarray.fill() method is used to fill the numpy array with a scalar value.
🌐
Programming Idioms
programming-idioms.org › idiom › 314 › fill-array-with-value › 7592 › python
Fill array with value, in Python
August 25, 2022 - Fill array with random bytes · Created a zeroed list of integers · Clear a byte array · Cheatsheets · Issues · Report a bug · × · Python · x = [v] * len(x) Python · for index in range(len(x)): x[index] = v · Python · x[:] = [v] * len(x) C++ x.fill(v); C++ fill(begin(x), end(x), ...
🌐
NumPy
numpy.org › doc › stable › reference › generated › numpy.ndarray.fill.html
numpy.ndarray.fill — NumPy v2.5 Manual
>>> import numpy as np >>> a = np.array([1, 2]) >>> a.fill(0) >>> a array([0, 0]) >>> a = np.empty(2) >>> a.fill(1) >>> a array([1., 1.])
🌐
Reddit
reddit.com › r/learnpython › how to fill a matrix using numpy
r/learnpython on Reddit: How to fill a matrix using numpy
June 18, 2020 -

Hello everyone,

I haven't done any type of linear algebra work with python before, only matlab. In matlab you create a matrix with the proper dimensions, then start filling it up with vectors of the appropriate size. I've tried to look up how to do this in python using a loop, and it doesn't seem as straightforward. It seems you first need to create a list, and append that list. Then convert that list to a numpy array. And then from there it appears you stack them? But stacking seems to only stack 1D and 2D arrays, so it's not exactly what I'm looking for.

For example:

import numpy as np
matrix=np.zeros((rows,columns))
list=[]
for i in range(columns):
    for x in range(rows):
        list.append(x)
    arr=np.array(list)
    matrix.append(arr) 
    list.clear()   

So in the above case, I've made a list, and converted it into an array with shape (rows, 1). Then I want to add it to the first column of my matrix. Then through the loop, I start to fill my matrix up by filling it one by one with these vectors. However, the issue is I'm trying to add a 1D array, to a multi-D matrix (which numpy doesn't allow you to do).

Hpw do I fill up a matrix using numpy?

Find elsewhere
🌐
Medium
medium.com › @amit25173 › what-is-numpy-fill-and-when-to-use-it-6c6192c67b9d
What is numpy.fill and When to Use It? | by Amit Yadav | Medium
February 9, 2025 - You start with an array containing [1, 2, 3, 4, 5]. The fill() method replaces all the values with 0.
🌐
NumPy
numpy.org › devdocs › reference › generated › numpy.ndarray.fill.html
numpy.ndarray.fill — NumPy v2.6.dev0 Manual
>>> import numpy as np >>> a = np.array([1, 2]) >>> a.fill(0) >>> a array([0, 0]) >>> a = np.empty(2) >>> a.fill(1) >>> a array([1., 1.])
🌐
Statology
statology.org › home › how to fill numpy array with values (2 examples)
How to Fill NumPy Array with Values (2 Examples)
July 21, 2022 - The following code shows how to use the np.full() function to fill up a NumPy array of length 10 with the value 3 in each position:
🌐
NumPy
numpy.org › doc › 2.0 › reference › generated › numpy.ndarray.fill.html
numpy.ndarray.fill — NumPy v2.0 Manual
>>> a = np.array([1, 2]) >>> a.fill(0) >>> a array([0, 0]) >>> a = np.empty(2) >>> a.fill(1) >>> a array([1., 1.])
🌐
Delft Stack
delftstack.com › home › howto › numpy › python fill array with value
How to Fill Array With Value in NumPy | Delft Stack
March 11, 2025 - In this example, we first import the NumPy library and define the shape of our array as a tuple (3, 4), meaning we want a 3x4 array. We set the fill_value to 7. The np.full() function then creates a new array of the specified shape, filled entirely ...
🌐
GeeksforGeeks
geeksforgeeks.org › dsa › array-fill
Array fill - GeeksforGeeks
2 weeks ago - The idea is to use the library fill() function to replace all elements of the array with the given value k.
🌐
Super Fast Python
superfastpython.com › numpy-parallel-array-fill
Parallel Numpy Array Fill (up to 3x faster) – SuperFastPython
May 24, 2023 - Numpy will release the global interpreter lock (GIL) when calling a fill function, allowing Python threads to run in parallel and populate different sub-arrays of a large shared array.
🌐
OpenSourceOptions
opensourceoptions.com › fill-numpy-arrays-with-numpy-fill-and-numpy-full
Fill NumPy Arrays with numpy.fill and numpy.full – OpenSourceOptions
We’ll start with a demonstration of how to change all the values in an existing array (numpy.fill()), then move on the to built-in function to initialize arrays with specific values.
🌐
GitHub
gist.github.com › rledford › 0e4fd58b1a7ffc3d9ac6a695e31912fc
Python Array - Fill · GitHub
Python Array - Fill. GitHub Gist: instantly share code, notes, and snippets.
🌐
Java2Blog
java2blog.com › home › python › python array › fill array with random numbers in python
Fill Array with Random Numbers in Python - Java2Blog
June 27, 2022 - As discussed earlier, the numpy library has a random module that can help in generating random numbers for numpy arrays. The randint() function can be used to generate an array of the required size and fill array with random numbers in Python.
🌐
NumPy
numpy.org › doc › 2.2 › reference › generated › numpy.ndarray.fill.html
numpy.ndarray.fill — NumPy v2.2 Manual
>>> import numpy as np >>> a = np.array([1, 2]) >>> a.fill(0) >>> a array([0, 0]) >>> a = np.empty(2) >>> a.fill(1) >>> a array([1., 1.])
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › numpy fill() function with examples
NumPy fill() Function with Examples - Spark By {Examples}
March 27, 2024 - NumPy fill() function in Python is used to fill the array with a scalar value. This function fills the elements of an array with a static value from the