You can try this:

import numpy as np
listvals = []
for i in range(10):
    listvals.append((xc, yc))
mat_vals = np.vstack(listvals)

This will output an ndarray like this:

[[ 2  0]
 [ 3  1]
 [ 4  2]
 [ 5  3]
 [ 6  4]
 [ 7  5]
 [ 8  6]
 [ 9  7]
 [10  8]
 [11  9]]

Or this maybe is better:

import numpy as np
list_xc = []
list_yc = []
for i in np.arange(10): 
    list_xc.append(xc)
    list_yc.append(yc)
mat_xc = np.asarray(list_xc)
mat_yc = np.asarray(list_yc)
mat_f = np.column_stack((mat_xc, mat_yc))
Answer from Litwos on Stack Overflow
🌐
Snakify
snakify.org › two-dimensional lists (arrays)
Two-dimensional lists (arrays) - Learn Python 3 - Snakify
To process 2-dimensional array, you typically use nested loops. The first loop iterates through the row number, the second loop runs through the elements inside of a row.
Discussions

How can I create multiple arrays using a for loop or to convert into a 2D array
If you are using numpy and want output like this: array1 = [1, 2, 3] array2 = [3, 2, 1] result = [[3, 2, 1], [6, 4, 2], [9, 6, 3]] you can use np.outer(): np.outer(array1, array2) Edit: Not sure why this was downvoted, but this produces the output u/maybethisonework wants according to their comment above. np.outer([5, 1, 6, 2], [1, 5, 3, 9]) ## [[5,25,15,45], [1,5,3,9], ...] More on reddit.com
🌐 r/learnpython
14
2
May 20, 2020
python - Creating 2D arrays and input values in it with a while loop? - Stack Overflow
Those loops set in a 2D array each time value. value can be in this case whatever you want it to be. The first index determines the array in the array and the second index selects the value in the nested array. In your case when you have [[1, 2, 3], [4, 5, 6], [7, 8, 9]], array[1][2] == 6 · This also works for arrays that are not symmetric. ... Oups! Lists are mutable objects in Python... More on stackoverflow.com
🌐 stackoverflow.com
How to create 2d NumPy array with for loop [Python] - Stack Overflow
Get a problem There is a double cycle, on the secondary loop we get an array of 10 elements. Then, after each cycle (first), you need to add these elements to the array. At the output, you need to ... More on stackoverflow.com
🌐 stackoverflow.com
May 17, 2018
loops - Iterating over a 2 dimensional python list - Stack Overflow
I have created a 2 dimension array like: rows =3 columns= 2 mylist = [[0 for x in range(columns)] for x in range(rows)] for i in range(rows): for j in range(columns): mylist[i][j] = '% More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-using-2d-arrays-lists-the-right-way
Using 2D arrays/lists in Python - GeeksforGeeks
The code below, compares two ways of initializing a 2D list in Python. Using list multiplication ([[0]*cols]*rows) creates multiple references to the same inner list, causing aliasing where changes affect all rows. Using a nested list comprehension creates a separate list for each row, avoiding aliasing and correctly forming a 2D array.
Published: December 20, 2025
🌐
Reddit
reddit.com › r/learnpython › how can i create multiple arrays using a for loop or to convert into a 2d array
r/learnpython on Reddit: How can I create multiple arrays using a for loop or to convert into a 2D array
May 20, 2020 -

I have this two arrays

array1 = [1. 0.91 0.8 0.68 0.61 0.57 0.52 0.46 0.39 0.3 ]

array2 = [188.38188649 201.69718164 210.51306563 221.65195842 229.91542541 238.11787625 257.072488 ]

I need to multiple the second array by each value in the first one. I have tried using a for loop like this

for i in range (array1):
    new_array = array2 * array1[i]

But it shows me this error

TypeError: only integer scalar arrays can be converted to a scalar index

Any help is appreciated, thank you.

🌐
TutorialsPoint
tutorialspoint.com › python_data_structure › python_2darray.htm
Python - 2-D Array
To print out the entire two dimensional array we can use python for loop as shown below.
🌐
Finxter
blog.finxter.com › home › learn python blog › how to create a two dimensional array in python?
How To Create a Two Dimensional Array in Python? - Be on the Right Side of Change
June 11, 2022 - Finally, we print the array with the help of a for loop by simply displaying the keys of the dictionary which are storing the lists, i.e., the individual rows of the 2D array. The most convenient way of working with arrays in Python is to use Python’s Numpy library.
🌐
Scaler
scaler.com › home › topics › 2d array in python
2D Array in Python | Python Two-Dimensional Array - Scaler Topics
May 25, 2026 - Traversing in a 2D array in python is commonly done with a nested loop. We can iterate through the outer array first, with the outer loop helping process all the rows in sequence, and then at each element of the outer array, we have another array, our internal array containing the elements.
Find elsewhere
🌐
CodeSignal
codesignal.com › learn › courses › multidimensional-arrays-and-their-traversal-in-python › lessons › exploring-the-dimensions-a-beginners-guide-to-multidimensional-arrays-in-python
Exploring the Dimensions: A Beginner's Guide to Multidimensional Arrays in Python | CodeSignal Learn
Python · array = [["Apt 101", "Apt 102", "Apt 103"], ["Apt 201", "Exit Floor", "Apt 203"], ["Apt 301", "Apt 302", "Apt 303"]] # Loop through 2D array for floor in array: for unit in floor: print(unit, end =', ') print() """ Prints: Apt 101, Apt 102, Apt 103, Apt 201, Exit Floor, Apt 203, Apt 301, Apt 302, Apt 303, """ Python ·
🌐
Guru99
guru99.com › home › python › python 2d arrays: two-dimensional list examples
Python 2D Arrays: Two-Dimensional List Examples
October 7, 2026 - In Python, a 2D array is normally implemented as a list of lists, so the two terms mean the same thing. For fast numeric work, the NumPy library offers a dedicated true array type.
🌐
Python Guides
pythonguides.com › initialize-a-2d-array-in-python
How to Initialize a 2D Array in Python? (2026 Guide)
September 22, 2026 - Each row is a fresh, independent object, so updating row 3 will never affect row 7. This is the safest go-to method for most beginners, and it pairs well with the reference guide on how to initialize a 2D array in Python for more variations. Sometimes you cannot write your starting values as a single expression. Maybe the value depends on the employee’s office, or comes from another data source. A loop gives you full control.
🌐
Upgrad
upgrad.com › home › tutorials › software & tech › 2d array in python
Comprehensive Guide to 2D Arrays in Python: Creation, Access, and Use
November 11, 2024 - Ensure that your code accounts for edge cases, such as the first and last rows and columns. ... # Check if a specific element is within bounds if 0 <= row < num_rows and 0 <= col < num_cols: value = array[row][col] else: print("Element is out of bounds.") ... 2d list Python comprehension is a concise and readable way to create and modify 2D arrays.
🌐
Google
sites.google.com › rgc.aberdeen.sch.uk › rgcahcomputingrevision › software-design › data-types-and-structures › 2d-arrays
Advanced Higher Computing Revision - 2D Arrays
You will see that just like 1D ... as below: In order to traverse through a 2D array - we will usually need to use a nested loop structure....
🌐
YouTube
youtube.com › watch
2.3.2 - Using a loop to create a 2D array (Python) - YouTube
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
Published: January 22, 2019
🌐
iO Flood
ioflood.com › blog › python-2d-array
Python 2D Array with Lists | Guide (With Examples)
February 10, 2024 - The outer loop iterates over the rows, and the inner loop iterates over each row’s elements. Here’s an example: for row in array: for elem in row: print(elem, end=' ') print() # Output: # 10 2 3 # 4 5 6 # 7 8 9 · In this example, we printed each element in the 2D array, with each row’s elements separated by a space and each row separated by a new line. Once you’ve grasped the basics of 2D arrays in Python...
🌐
Medium
theizharahmad.medium.com › 2d-arrays-in-python-08ff7c287b2a
2D Arrays in Python. 2D arrays, also known as a matrix, are… | by Izhar Ahmad | Medium
September 7, 2024 - Similarly, we use nested for loops to iterate over a 2D array: for row in table: for col in row: print(col) … or alternatively, we can use unpacking method: for col1, col2, col3, col4 in table: print(col1, col2, col3, col4) If we have to create ...
🌐
Stack Overflow
stackoverflow.com › questions › 16548668 › iterating-over-a-2-dimensional-python-list
loops - Iterating over a 2 dimensional python list - Stack Overflow
I have created a 2 dimension array like: rows =3 columns= 2 mylist = [[0 for x in range(columns)] for x in range(rows)] for i in range(rows): for j in range(columns): mylist[i][j] = '%...
Top answer
1 of 7
1263

You're technically trying to index an uninitialized array. You have to first initialize the outer list with lists before adding items; Python calls this "list comprehension".

# Creates a list containing 5 lists, each of 8 items, all set to 0
w, h = 8, 5
Matrix = [[0 for x in range(w)] for y in range(h)] 

#You can now add items to the list:

Matrix[0][0] = 1
Matrix[6][0] = 3 # error! range... 
Matrix[0][6] = 3 # valid

Note that the matrix is "y" address major, in other words, the "y index" comes before the "x index".

print Matrix[0][0] # prints 1
x, y = 0, 6 
print Matrix[x][y] # prints 3; be careful with indexing! 

Although you can name them as you wish, I look at it this way to avoid some confusion that could arise with the indexing, if you use "x" for both the inner and outer lists, and want a non-square Matrix.

2 of 7
487

If you really want a matrix, you might be better off using numpy. Matrix operations in numpy most often use an array type with two dimensions. There are many ways to create a new array; one of the most useful is the zeros function, which takes a shape parameter and returns an array of the given shape, with the values initialized to zero:

>>> import numpy
>>> numpy.zeros((5, 5))
array([[ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.],
       [ 0.,  0.,  0.,  0.,  0.]])

Here are some other ways to create 2-d arrays and matrices (with output removed for compactness):

numpy.arange(25).reshape((5, 5))         # create a 1-d range and reshape
numpy.array(range(25)).reshape((5, 5))   # pass a Python range and reshape
numpy.array([5] * 25).reshape((5, 5))    # pass a Python list and reshape
numpy.empty((5, 5))                      # allocate, but don't initialize
numpy.ones((5, 5))                       # initialize with ones

numpy provides a matrix type as well, but it is no longer recommended for any use, and may be removed from numpy in the future.