I want to make a 2D array (not list) from 2 given lists. How would I do that? For example, I want to generate a 2D 2by5 array with the list [1,2,3,4,5] and [6,7,5,9,34] And also how would I iterate that array. I have tried this
#import the necessary module
import array as arr
list1 = [2,3,5,7,1]
list2 = [13,17,19,23,29]
myarr = arr.array('i')
index = 0
for i in list1:
myarr[0][index] = i
index = index+1
index = 0
for i in list2:
myarr[1][index] = i
index = index+1
print(myarr)
Got the error
Traceback (most recent call last):
File "temp.py", line 10, in <module>
myarr[0][index] = i
IndexError: array index out of range
arraymodule does not support multidimensional arrays.numpy, then why must you use thearraymodule?